python - Getting value of specific key in a dictionary -


i have dictionary so:

li = {'a': 'apple', 'b': 'benana', 'c': 'cherry'} 

so have:

>>> key, value in li.items(): ...     print key, value ...  apple c cherry b benana >>>  

i want say:

if param == 'a':     print value # here want value of `a` key only! 

i want print apple only.

you can use:

li['a']  >>> li = {'a': 'apple', 'b': 'benana', 'c': 'cherry'} >>> li['a'] 'apple' 

Comments

Popular posts from this blog

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -