1

For example, I'll make a dictionary like this:

a_dict = {'name': ('John', 'James'), 'animal': ('chicken', 'goat')}

Is there any way for me to scan a user input, for example, if the user input a goat, I want to return a list like this:

a_list = [('animal', 'goat')]
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
  • Why would the search term be part of the result list? Doesn't that make it unnecessarily complicated? Also, what would the result look like if there are two or more keys in the dictionary in whose values the search term can be found? – Tim Pietzcker Mar 15 '16 at 06:56
  • @TimPietzcker Actually I am doing an exercise from [link](http://learnpythonthehardway.org/book/ex48.html). I need to kinda like to analysis the user's input to make a command line game more flexible (don't really know if I use the right expression here). – Hafiz Hilman Mohammad Sofian Mar 15 '16 at 07:00
  • 1
    This question is a duplicate, to get an exact answer to your problem, see this image http://i.stack.imgur.com/0EjPl.png of my (now deleted) answer – Bhargav Rao Mar 15 '16 at 07:07
  • @BhargavRao Thanks! Greatly appreciated. – Hafiz Hilman Mohammad Sofian Mar 15 '16 at 07:19

0 Answers0