belongs to collection: Python Dictionary Exercises
We know how to check if the key exists in a dictionary. Sometimes it is required to check if the given value is present.
Write a Python program to check if value 200 exists in the following dictionary.
Given:
sample_dict = {'a': 100, 'b': 200, 'c': 300}
Expected output:
200 present in a dict
Hint:
values()
Solution:
sample_dict = {'a': 100, 'b': 200, 'c': 300} if 200 in sample_dict.values(): print('200 present in a dict')
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Hint:
values()
method.Solution:
need an explanation for this answer? contact us directly to get an explanation for this answer