python bijection

Francis Carr coldtortuga at gmail.com
Fri Nov 27 19:12:36 CET 2009


I was really inspired by this discussion thread! :-)

After much tinkering, I think I have a simpler solution.  Just make
the inverse mapping accessible via an attribute, -AND- bind the
inverse of -THAT- mapping back to the original.  The result is a
python dict with NO NEW METHODS except this inverse-mapping
attribute.  I have posted it on code.activestate.com as <a
href="http://code.activestate.com/recipes/576968/">Recipe 576968:
Flipdict -- python dict that also maintains a one-to-one inverse
mapping</a>

 -- F. Carr



More information about the Python-list mailing list