how to find key of a value in a dictionary
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.
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"
Join our real-time social learning platform and learn together with your friends!