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 174 views
1 answer 182 views
2 answers 160 views
1 answer 187 views
1 answer 169 views
1 answer 200 views
...