Nested Dictionary

YouΒ 
canΒ 
storeΒ 
theΒ 
multipleΒ 
values
Β 
inΒ 
aΒ 
list,Β 
andΒ 
useΒ 
theΒ 
listΒ 
variableΒ 
asΒ 
theΒ 
valueΒ 
toΒ 
theΒ 
key.
YouΒ 
canΒ 
alsoΒ 
youΒ 
otherΒ 
dataΒ 
structuresΒ 
likeΒ 
tuple,Β 
set,Β 
orΒ 
evenΒ 
anotherΒ 
dictionaryΒ 
toΒ 
createΒ 
aΒ 
nestedΒ 
dictionary.
dict_name = { key : list_variable }
list_age = [14, 21]
dict_1 = { 'ages' : list_age }
print(dict_1)

Accessing the values of nested dictionary

SinceΒ 
aΒ 
listΒ 
orΒ 
anotherΒ 
dataΒ 
structureΒ 
isΒ 
storedΒ 
asΒ 
aΒ 
value,Β 
weΒ 
firstΒ 
accessΒ 
itΒ 
asΒ 
theΒ 
value
Β 
of
Β 
the
Β 
key
Β 
inΒ 
theΒ 
Dictionary,Β 
andΒ 
thenΒ 
weΒ 
accessΒ 
theΒ 
index/keyΒ 
ofΒ 
thatΒ 
dataΒ 
structureΒ 
toΒ 
getΒ 
theΒ 
valueΒ 
weΒ 
want.
print(dict_name[key][index])
list_age = [14, 21]
dict_1 = { 'ages' : list_age }
print(dict_1['ages'][0])

dict_in_dict = {
    'students':{
        1:'Theo',
        2:'Ron',
        3:'Harry'
    }
}
print(dict_in_dict['students'][1])