There are two common ways to iterate over a dictionary in Python. To iterate over the keys:
for key in my_dict:
print(key)
To iterate over both the keys and values:
for key, val in my_dict.items():
print(key, val)
There are two common ways to iterate over a dictionary in Python. To iterate over the keys:
for key in my_dict:
print(key)
To iterate over both the keys and values:
for key, val in my_dict.items():
print(key, val)