If I have a list of tuples, where each tuple represents variables,
c, how can I eliminate redundant tuples?
Redundant tuples are those where
b are simply interchanged, but
c is the same. So for this example:
tups = [(30, 40, 50), (40, 30, 50), (20, 48, 52), (48, 20, 52)]
my final list should only contain only half of the entries. One possible output:
tups = [(30, 40, 50), (20, 48, 52)]
tups = [(40, 30, 50), (20, 48, 52)]
Is there an easy Pythonic way to do this?
I tried using sets, but
(30, 40, 50) is different from
(40, 30, 50), but to me these are redundant and I'd just like to keep one of them (doesn't matter which, but if I could pick I'd prefer the low to high value order). If there was a way to sort the first 2 elements of the tuples, then using the set would work.
I am sure I could hack together a working solution (perhaps converting tuples to lists as intermediate step), but I just wanted to see if there's an easy and obvious way to do this that I'm not familiar with.
PS: This question partially motivated by PE #39. But even aside from this PE problem, I am now just curious how this could be done easily (or if).
Just to provide a bit of context for those not familiar with PE #39 -
c represent sides of a right triangle, so I'm checking if
a**2 + b**2 == c**2, clearly the order of
b don't matter.