EN
Python - nested dictionary
0 points
In this article, we would like to show you nested dictionary in Python.
Below we present example nested dictionary of users.
xxxxxxxxxx
1
users = {
2
"user1": {
3
"name": "Tom",
4
"age": 30
5
},
6
"user2": {
7
"name": "Kate",
8
"age": 23
9
},
10
"user3": {
11
"name": "Ann",
12
"age": 25
13
}
14
}
You can also create a nested dictionary from existing dictionaries in the following way:
xxxxxxxxxx
1
# dictionaries
2
user1 = {
3
"name": "Tom",
4
"age": 30
5
}
6
user2 = {
7
"name": "Kate",
8
"age": 23
9
}
10
user3 = {
11
"name": "Ann",
12
"age": 25
13
}
14
15
# nested dictionary
16
users = {
17
"user1": user1,
18
"user2": user2,
19
"user3": user3
20
}