Ace school

with brainly

  • Get help from millions of students
  • Learn from experts with step-by-step explanations
  • Level-up by helping others

A community for students.

how to find key of a value in a dictionary

MIT 6.00 Intro Computer Science (OCW)
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.

Join Brainly to access

this expert answer

SEE EXPERT ANSWER

To see the expert answer you'll need to create a free account at Brainly

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..
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
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.

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

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
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]
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
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
thanks but i dont have credit card yet.. :( well where can i find videos apart from MIT 6.0
i have one book of python beginning python (wrox publication) is it good enough?
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
thanks bro thanks a lot.. :) do you have facebook a/c?
yes, I never use it but I have one.. is /Fidel.sanchez.bueno
thanks well the google video starts from part3 i wondor where are the other 2 parts from day1
http://code.google.com/edu/languages/google-python-class/ on the left in "Lecture Videos"

Not the answer you are looking for?

Search for more explanations.

Ask your own question