python bijection

Carl Banks pavlovevidence at
Fri Nov 20 03:17:36 CET 2009

On Nov 19, 3:24 pm, Joshua Bronson <jabron... at> wrote:
> I couldn't find a library providing a bijective map data structure
> (allowing for constant-time lookups by value) in the few minutes I
> looked, so I took a few more minutes to code one up:
> Is this at all worth releasing? Comments and suggestions welcome.

Apart from the GPL, it seems perfectly fine to release, and looks like
an interesting strategy.  I've wanted one of those once in a while,
never enough to bother looking for one or writing one myself.

But you should absolutely not inherit from dict if you're overriding
all it's methods.  It's useless and wasteful to do that, perhaps
dangerous.  You end up using bytes for a small hash table that's never

Plus Python 3 has a notion of Abstract Base Classes: it will allow
customization of isinstance to advertise that your class implements
MutableMapping, which is the right way to do it.

Carl Banks

More information about the Python-list mailing list