find dict in dict python code example
Example 1: search in dict python
dictionary = { "key1" : 1, "name" : "Jordan", "age" : 21 }
for key in dictionary.keys():
print("the key is {} and the value is {}".format(key, dictionary[key]))
Example 2: dict of dict python
nested_dict = { 'dictA': {'key_1': 'value_1'},
'dictB': {'key_2': 'value_2'}}
Example 3: find a key in a dictionary python
fruits = {'apple': 2, 'pear': 5, 'strawberry': 3}
if 'apple' in fruits:
print("Key found!")
else:
print("Key not found!")