Given the below object, how to add a new city "losangeles" in "california"? Given a country, state, city and attributes for the city, how can I update the object? (I am pretty new to python)
myplaces = {
"unitedstates": {
"california": {
"sanfrancisco": {
"description": "Tech heaven",
"population": 1234,
"keyplaces": ["someplace1",
"someplace2"]
}
}
},
"india": {
"karnataka": {
"bangalore": {
"description": "IT hub of India",
"population": 12345,
"keyplaces": ["jpnagar",
"brigade"]
},
"mysore": {
"description": "hostoric place",
"population": 12345,
"keyplaces": ["mysorepalace"]
}
}
}
}
I tried adding elements as below (like how it is done in PHP):
myplaces['unitedstates']['california']['losangeles']['description'] = 'Entertainment'
Edit: This is not a duplicate. I am looking for a generic way to add items.