0

I will be incrementally adding tuple pairs into a python set.

I would like the set to recognize 'duplicates' as tuples which have the same contents regardless of order.

For example, if I add the following tuples:

([1, 0], [1, 1])
([1, 0], [0, 0])
([1, 1], [0, 0])
([1, 1], [1, 0])

I would like the set to discard the fourth item, as it is a 'duplicate' of the first. I wish I could do this with sets, but alas, they are unhashable.

Is there a simple way to do this?

pixelpax
  • 1,435
  • 13
  • 22
  • you need to iterate over elements of set and check they are all the same, I dont really see any shortcut available here :/ – Mixone Apr 17 '16 at 19:21
  • Of course, `frozenset` won't magically make unhashable tuples hashable. You'll need to deal with inner lists e.g. convert them to tuples or `frozenset`s. – vaultah Apr 17 '16 at 19:27

0 Answers0