Reverse dictionnary

Skip Montanaro skip at pobox.com
Fri Nov 15 06:25:22 EST 2002


    Julien> Does "reverse dictionnary" exists in python ?

Nope.

    Julien> If this does not exists, I will simply do two dictionnaries, 

That's the usual technique, though this only works properly for one-to-one
mappings.  If your keys and values are truly of different types you can just
use one dictionary:

  d1 = {
    1:"str1",
    2:"str2",
    "str1":1,
    "str2":2
  }

-- 
Skip Montanaro - skip at pobox.com
http://www.mojam.com/
http://www.musi-cal.com/




More information about the Python-list mailing list