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
Post a Comment