If you have many such pairs, using frozenset() NOT a good idea. Use tuples instead.
>>> import sys >>> fs1 = frozenset([42, 666]) >>> fs2 = frozenset([666, 42]) >>> fs1 == fs2 True >>> t1 = tuple(sorted([42, 666])) >>> t2 = tuple(sorted([666, 42])) >>> t1 == t2 True >>> sys.getsizeof(fs1) 116 >>> sys.getsizeof(t1) 36 >>>
Update Bonus: Sorted tuples have a predictable iteration sequence:
>>> for thing in fs1, fs2, t1, t2: print [x for x in thing] ... [42, 666] [666, 42] [42, 666] [42, 666] >>>
Update 2 ... and their repr () are the same thing:
>>> repr(fs1) 'frozenset([42, 666])' >>> repr(fs2) 'frozenset([666, 42])'
John machin
source share