Skip to content Skip to sidebar Skip to footer

Removing Permutations From A List Of Tuples

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

Solution 1:

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)])

Post a Comment for "Removing Permutations From A List Of Tuples"