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

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -