Dual look-up on keys?

Vlastimil Brom vlastimil.brom at gmail.com
Thu Mar 6 00:18:01 CET 2008


2008/3/5, castironpi at gmail.com <castironpi at gmail.com>:
>
> ...
> Anyway, if (a,b) is a key in dictionary d, can it guarantee that (b,a)
> is also in it, and maps to the same object?
> ...
>

Well, it's probably not the most effective way, but one can use something
like:

>>> d={frozenset(("a","b")):7}
>>> d[frozenset(("b","a"))]
7
>>> d[frozenset(("b","a"))]=94
>>> d[frozenset(("a","b"))]
94
>>>

HTH

vbr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080306/bf728ae3/attachment.html>


More information about the Python-list mailing list