A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a Python program to check if value 200 exists in the following dictionary.
Q:

Write a Python program to check if value 200 exists in the following dictionary.

0

Check if a value exists in a dictionary

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Hint:

  • Get all values of a dict in a list using the values() method.
  • Next, use the if condition to check if 200 is present in the given list

Solution:

sample_dict = {'a': 100, 'b': 200, 'c': 300}
if 200 in sample_dict.values():
    print('200 present in a dict')

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now