Python symmetric pair data type

python

Solution

You are looking for a `set()` type:

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

`set`s have no ordering. If you need to use these as keys in a dictionary, use the immutable `frozenset()` type instead. `frozenset`s are to `set`s what `tuple`s are to `list`s.

There is but one limitation: just like dictionary keys, to be able to put values into a `set`, they need to be hashable, which usually comes down to no mutable types.

Also, values in a set must all be unique; `{'a', 'a'}` is reduced to `{'a'}`, a set of just one value. You can use `collection.Counter()` objects if your pairs need to support a repeated value.

Problem

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

Original source