EN
Python - iterate through dictionary
0
points
In this article, we would like to show you how to iterate through dictionary in Python.
Quick solution:
for key in dictionary:
print(key)
Practical example
Example 1 - print keys
In this example, we use simple for loop to iterate through the dictionary and print all its keys.
my_dict = {
"id": 1,
"name": "Tom",
"age": 25
}
for item in my_dict:
print(item)
Output:
id
name
age
Example 2 - print values
In this example, we use simple for loop to iterate through the dictionary and print all its values.
my_dict = {
"id": 1,
"name": "Tom",
"age": 25
}
for key in my_dict:
print(my_dict[key])
Output:
1
Tom
25