I’ve a dictionary with a (x,y) key, where (x,y) means the same as (y,x), How should I do this ?
I can do:
>>> d = {(1,2): "foo"}
>>> i = d.get(2,1)
>>> if i is None:
... i = d.get((1,2))
...
>>> i
'foo'
Is there a better way of doing this, so d.get((2,1)) would match the key (1,2) directly ?
ideally i’d want to insert e.g. (2,1) and not have it be distinct from the (1,2) key as well.
Use frozensets rather than tuples.