How to check if a value exists in a dictionary using Python

2 Answers

0 votes
dic = {'a': 'python', 'b': 'java', 'c': 'php', 'd': "c++"}

if 'java' in dic.values():
    print('yes')
else:
    print('no')

 
'''
run:
 
yes
 
'''

 



answered Dec 5, 2017 by avibootz
0 votes
dic = {'a': 'python', 'b': 'java', 'c': 'php', 'd': "c++"}

s = 'php'
if s in dic.values():
    print('yes')
else:
    print('no')

 
'''
run:
 
yes
 
'''

 



answered Dec 6, 2017 by avibootz

Related questions

1 answer 166 views
1 answer 173 views
2 answers 152 views
1 answer 181 views
1 answer 162 views
1 answer 195 views
...