
In my experience, the implementation of bijective dict is largely application specific. 1. Unique-valued dict is fairly straight forward and there is little ambiguity on implementation using 2 dicts. 2. However, if values are not to be unique, then it largely depends on application. (best (as in most efficient) pypi I have found for this: https://pypi.org/project/indexed/ <https://pypi.org/project/indexed/>) But to me it feels that there is some sort of gap in container space. E.g. I have spent a reasonable amount of time on: a) 1-2-1 dict b) many-2-many dict c) dict-deque d) bijective-dict-deque e) list-dict Maybe it would be good to have similar package to `more_itertools`. E.g. `more_collections`, where assorted recipes are implemented. I am not a fan of making my libraries dependent on less known pypi packages, but when a package is referenced in python official docs, then I am much more at ease.
On 30 Jun 2023, at 04:50, Andre Delfino <adelfino@gmail.com> wrote:
A dict method to retrieve the key of a value from a bijective dict would have come in handy to me in several occasions:
names = {'one': 1} names.inverse()[1] 'one' names = {'one': 1, 'uno': 1} names.inverse()[1] ValueError: dict is not bijective
My usual use case is when both keys and values have simple types like int/str, like:
{ 'account-a': 123, 'account-b': 456, }
Users may enter the account name, or the ID. The system works with the account ID (translating from the account name if needed), but when it needs to mention the account to the user, it shows the account name instead.
I do understand that retrieval wouldn't be O(1). _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/BWMIAS... Code of Conduct: http://python.org/psf/codeofconduct/