You can use something like this. I used frozenset
because it allows to be hashed and like set
it doesn't care about the order - so takes care of your palindromes and duplicates:
from iteration_utilities import unique_everseen
from itertools import chain
a = [(0, 1), (0, 2), (3, 0)]
b = [(4, 5), (2, 0)]
c = [(2, 6), (5,3)]
lists = [a, b, c]
A sample run:
>>> list(unique_everseen(chain.from_iterable(lists), key=frozenset))
[(0, 1), (0, 2), (3, 0), (4, 5), (2, 6), (5, 3)]
The recipe for unique_everseen
can also be borrowed from the itertools python documentation page if you don't want an external module.
And if you have items with more than 2 elements you could use this as unique_everseen
-function. (slightly changed from the recipe):
def remove_duplicates_and_reversed(iterable):
seen = set()
for item in iterable:
if item not in seen:
seen.add(item) # takes care of duplicates
seen.add(item[::-1]) # takes care of reversed duplicates
yield item
>>> list(remove_duplicates_and_reversed(chain.from_iterable(lists)))
[(0, 1), (0, 2), (3, 0), (4, 5), (2, 6), (5, 3)]