Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 18 Online
OpenStudy (anonymous):

how to find key of a value in a dictionary

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

OpenStudy (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

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

OpenStudy (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

OpenStudy (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]

OpenStudy (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

OpenStudy (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

OpenStudy (anonymous):

thanks but i dont have credit card yet.. :( well where can i find videos apart from MIT 6.0

OpenStudy (anonymous):

i have one book of python beginning python (wrox publication) is it good enough?

OpenStudy (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

OpenStudy (anonymous):

thanks bro thanks a lot.. :) do you have facebook a/c?

OpenStudy (anonymous):

yes, I never use it but I have one.. is /Fidel.sanchez.bueno

OpenStudy (anonymous):

thanks well the google video starts from part3 i wondor where are the other 2 parts from day1

OpenStudy (anonymous):

http://code.google.com/edu/languages/google-python-class/ on the left in "Lecture Videos"

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!