Hello,
Using iteritems would be much easier approach
Something like this
mydic = {"A": "Apple", "B": "Banana"}
for key, value in mydic.iteritems(): if value == "Apple": print key
Thanks & BR, Bharath Shetty
On Tuesday, 3 May 2016 2:57 AM, Jason N. via Tutor <[email protected]> wrote:
Thank you all for your responses.
A quick follow up, what is the best way to make dictionary requests case
in-sensitive? For example, "Apple and "apple" should bring back the same
dictionary response. Thank you.
On Monday, May 2, 2016 6:57 PM, Bob Gailer <[email protected]> wrote:
On May 2, 2016 5:27 PM, "Jason N. via Tutor" <[email protected]> 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.
I think this would depend on how big the data set is and how often you want to
look things up.
Two other Solutions:
Create a class which internally manages two dictionaries.
If things are really big create a database using for example sqlite.
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor