-3

I have a list like this [(1,2), (2,1), (3,4), (5,6), (6,5)]. How I can remove in python 3 one of sets with duplicate numbers? I want to get in output [(1,2), (3,4), (5,6)].

Bob Napkin
  • 566
  • 6
  • 15

1 Answers1

3

If the order of the results doesn't matter, it is a one liner:

>>> x = [(1,2), (2,1), (3,4), (5,6), (6,5)]
>>> list(set([ tuple(set(i)) for i in x ]))
[(1, 2), (5, 6), (3, 4)]
RobertB
  • 1,879
  • 10
  • 17