How to get a particular key from dictionary in python?
I have a dictionary as :
dict = {'redorange':'1', 'blackhawak':'2', 'garlicbread':'3'}
I want to get value of that key which contains garlic in its key name.
How I can achieve it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Let’s call your dictionary
d:prints a list of all corresponding values:
If you know you want a single value:
prints
This raises
StopIterationErrorif no such key/value is found. Add the default value:to get
Noneif such a key is not found (or use another default value).