EN
Python - nested dictionary
0
points
In this article, we would like to show you nested dictionary in Python.
Practical example
Below we present example nested dictionary of users.
users = {
"user1": {
"name": "Tom",
"age": 30
},
"user2": {
"name": "Kate",
"age": 23
},
"user3": {
"name": "Ann",
"age": 25
}
}
You can also create a nested dictionary from existing dictionaries in the following way:
# dictionaries
user1 = {
"name": "Tom",
"age": 30
}
user2 = {
"name": "Kate",
"age": 23
}
user3 = {
"name": "Ann",
"age": 25
}
# nested dictionary
users = {
"user1": user1,
"user2": user2,
"user3": user3
}