I would like to make a pair of two elements. I don\'t care about the order of the elements, so I use frozenset.
I can think of the following two methods t
Just to elaborate on an above comment, and assuming your elements are easily sortable, you could make an unordered pair class from tuple using:
class Pair(tuple):
def __new__(cls, seq=()):
assert len(seq) == 2
return tuple.__new__(tuple, sorted(seq))
Then you get:
>>> Pair((0, 1))
(0, 1)
>>> Pair((1, 0))
(0, 1)
>>> Pair((0, 1)) == Pair((1, 0))
True