Python symmetric pair data type

Is there a data type in python that takes a pair (a, b) and processes it symmetrically? That is, (a, b) is treated as the same as (b, a). It would be preferable not to have a code that manually checks if two pairs have equality, checking if places a and b are replaced.

+3
source share
1 answer

Are you looking for set()type :

>>> pair = {'a', 'b'}
>>> pair == {'b', 'a'}
True

sethave no order. If you need to use these keys in a dictionary, use an immutable frozenset()type instead . frozensetcorrespond set, which tupleis equal to lists.

: , set, , .

, ; {'a', 'a'} {'a'}, . collection.Counter() objects, .

+5

All Articles