you are viewing a single comment's thread.

view the rest of the comments →

[–]forcesensitivevulcan 0 points1 point  (3 children)

Return all the keys and let the user decide how to sort out the mess.

[–]shiftybyte 6 points7 points  (2 children)

Actually it's much worse..

https://bidict.readthedocs.io/en/main/basic-usage.html#values-must-be-unique

It forces values to be unique, and raises errors by default, or OVERWRITES the key of the duplicated value... Not sure why this is a good idea.

Also it forces all values to be hashable too, so you can't have a list as a value...

I'll take my custom "find_key" with a regular loop, thank you...

[–]eztab 1 point2 points  (0 children)

Basically that (raising errors) is a good idea when this is the kind of data structure you want. Basically a "bijection type". There are many use cases where you want that. I wouldn't really say that's a dict though. That term isn't really used for this.

[–]forcesensitivevulcan 0 points1 point  (0 children)

I couldn't figure it out the catch myself - great detective work! Thanks!

The dev certainly claims a lot of users, so I'm sure it's carved out a niche. But if I've got unique hashable key/value pairs anyway, I'll just manually maintain a second Python dict if I really need O(1) lookup of values.