Dictionary bidirectional

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sun Jul 13 21:18:06 EDT 2008


bukzor:
> You need to use two dictionaries. Here's a class that someone's
> written that wraps it up into a single dict-like object for you:
> http://www.faqts.com/knowledge_base/view.phtml/aid/4376

It contains code like:

try:
    del self.data[item]
except KeyError:
    pass

Exceptions are useful in python, but with dictionaries this is
probably faster (and shorter), even if it may perform two lookups:

if item in self.data:
    del self.data[item]

Bye,
bearophile



More information about the Python-list mailing list