I have a dictionary with a key (x,y), where it (x,y)means the same as (y,x). How should I do it?
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 to do this, so d.get((2,1))would it directly correspond to the key (1,2)? Ideally, I would like to insert, for example. (2,1)and should not be different from the key (1,2).
source
share