anonymous
  • anonymous
how to find key of a value in a dictionary
MIT 6.00 Intro Computer Science (OCW)
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • anonymous
excuse me, but why would you need that?.. the idea of dicts is using the keys as indexes to get values not the other way around..
anonymous
  • anonymous
okk basically i want input from user and check it agaist my dictionary values and return key like this: dict={'windows':['win 7','xp','NT'],'linux':['ubuntu','fedora','mint'} and if user enter win 7 it returns windows and so on
anonymous
  • anonymous
well you can do it, but you're implementing dictionaries wrong.. platform = {'windows' : ['win 7', 'xp', 'NT'], 'linux' : ['ubuntu', 'fedora', 'mint']} user_input = "xp" keys = platform.keys() for x in keys: for y in platform[x]: if y == user_input: print user_input I recommend that you restructure the dictionary, so that the versions or distros can be the indexes.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
thanks axl456 okk so now you know that this is the scene how would you use dict in this case? i could not understand the last line
anonymous
  • anonymous
you could use them like this: operating_system = {"xp" : ["windows",], "win 7" : ["windows",], "NT" : ["windows",], "ubuntu" : ["linux",], "fedora" : ["linux",], "mint" : ["linux",]} in this case every windows version or linux distro is an individual entry in the dict. This way you can add more info to every entry: operating_system = {"xp" : ["windows", "2001", "128 MB RAM", "1.5 GB"]... and use the OS as index, so if the user type "xp" you could just do this: operating_system[user_input]
anonymous
  • anonymous
thanks bro.. well i want to very familiar with dictionary and list its mutations how can i do that is there any book or something its really tough to make simple projects for beginners because as a programmer of C i know what i want to do but i can't implement it in python
anonymous
  • anonymous
well for python theres A LOT of book, videos, tutorial, etc etc on the internet.. the one I recommend most is this: http://www.amazon.com/Learning-Python-Powerful-Object-Oriented-Programming/dp/0596158068
anonymous
  • anonymous
thanks but i dont have credit card yet.. :( well where can i find videos apart from MIT 6.0
anonymous
  • anonymous
i have one book of python beginning python (wrox publication) is it good enough?
anonymous
  • anonymous
I havent seen this videos yet, but they look good: http://code.google.com/edu/languages/google-python-class/ this is the one of dict: http://www.youtube.com/watch?v=haycL41dAhg
anonymous
  • anonymous
thanks bro thanks a lot.. :) do you have facebook a/c?
anonymous
  • anonymous
yes, I never use it but I have one.. is /Fidel.sanchez.bueno
anonymous
  • anonymous
thanks well the google video starts from part3 i wondor where are the other 2 parts from day1
anonymous
  • anonymous
http://code.google.com/edu/languages/google-python-class/ on the left in "Lecture Videos"

Looking for something else?

Not the answer you are looking for? Search for more explanations.