[Tutor] Dictionary Question

Michael Selik michael.selik at gmail.com
Tue May 3 14:46:17 EDT 2016


On Mon, May 2, 2016 at 5:28 PM Jason N. via Tutor <tutor at python.org> wrote:

> Hello,
> Wanted to ask if its possible to have a dictionary that can be looked up
> by either values?
> For example,
> mydic = {"A: "Apple", "B": "Banana"}When user inputs "A" I want "Apple" to
> come. But if the user enter "Apple" I want "A" to respond.
> Please let me know the best way to handle this type cause instead of just
> created duplicate entries to cover all possibilities. Thank you.
>

A dictionary enforces that the keys are unique, but many keys may have the
same value. Do you want to enforce that values are unique? If not, does it
matter which key is returned if many keys have the same value?


More information about the Tutor mailing list