Any help with this question is appreciated.
I have a list of tuples
a = [(1,2), (2,1), (1,3), (1,4), (4,1)]
and I need to remove duplicates of a certain type: (1,2) and (2,1) are considered duplicates according to my definition. Required output
a = [(1,2), (1,3), (1,4)]
Thanks in advance
You could sort them and then remove duplicates with set()
:
>>> set(tuple(sorted(l)) for l in a)
set([(1, 2), (1, 3), (1, 4)])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With