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 -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/BWMIASE5YCDETFSZYAUG7TVWTMBFHKQW/
Code of Conduct: http://python.org/psf/codeofconduct/