I have dictionary with following format:
Demo code:
>>> import pprint
>>> pprint.pprint(data)
{'lookup': {'F01': '
.custom1 {
background-color: #f5e9dc;
padding: 10px;
border-radius: 10px;
font-family: sans-serif;
font-size: 0.9em;
margin-top: 1em;
}
.custom2 .style8-rw {
font-family: sans-serif;
font-weight: bold;
color: #F57215;
}',
'F02': '
.custom1 {
background-color: #f5e9dc;
padding: 10px;
border-radius: 10px;
font-family: sans-serif;
font-size: 0.9em;
margin-top: 1em;
}
.custom2 .style8-rw {
font-family: sans-serif;
font-weight: bold;
color: #F57215;
}',
'F03': '
.custom1 {
background-color: #f5e9dc;
padding: 10px;
border-radius: 10px;
font-family: sans-serif;
font-size: 0.9em;
margin-top: 1em;
}
.custom2 .style8-rw {
font-family: sans-serif;
font-weight: bold;
color: #F57215;
}',
'F04': '
.custom1 {
background-color: #f5e9dc;
padding: 10px;
border-radius: 10px;
font-family: sans-serif;
font-size: 0.9em;
margin-top: 1em;
}
.custom2 .style8-rw {
font-family: sans-serif;
font-weight: bold;
color: #F57215;
}',
'F05': '
.custom1 {
background-color: #f5e9dc;
padding: 10px;
border-radius: 10px;
font-family: sans-serif;
font-size: 0.9em;
margin-top: 1em;
}
.custom2 .style8-rw {
font-family: sans-serif;
font-weight: bold;
color: #F57215;
}',
'F06': '
.custom1 {
background-color: #f5e9dc;
padding: 10px;
border-radius: 10px;
font-family: sans-serif;
font-size: 0.9em;
margin-top: 1em;
}
.custom2 .style8-rw {
font-family: sans-serif;
font-weight: bold;
color: #F57215;
}',
'F07': '
.custom1 {
background-color: #f5e9dc;
padding: 10px;
border-radius: 10px;
font-family: sans-serif;
font-size: 0.9em;
margin-top: 1em;
}
.custom2 .style8-rw {
font-family: sans-serif;
font-weight: bold;
color: #F57215;
}',
'F08': '
.custom1 {
background-color: #f5e9dc;
padding: 10px;
border-radius: 10px;
font-family: sans-serif;
font-size: 0.9em;
margin-top: 1em;
}
.custom2 .style8-rw {
font-family: sans-serif;
font-weight: bold;
color: #F57215;
}',
'F09': '
.custom1 {
background-color: #f5e9dc;
padding: 10px;
border-radius: 10px;
font-family: sans-serif;
font-size: 0.9em;
margin-top: 1em;
}
.custom2 .style8-rw {
font-family: sans-serif;
font-weight: bold;
color: #F57215;
}',
'F10': '
.custom1 {
background-color: #f5e9dc;
padding: 10px;
border-radius: 10px;
font-family: sans-serif;
font-size: 0.9em;
margin-top: 1em;
}
.custom2 .style8-rw {
font-family: sans-serif;
font-weight: bold;
color: #F57215;
}',
'F11': '
.custom1 {
background-color: #f5e9dc;
padding: 10px;
border-radius: 10px;
font-family: sans-serif;
font-size: 0.9em;
margin-top: 1em;
}
.custom2 .style8-rw {
font-family: sans-serif;
font-weight: bold;
color: #F57215;
}',
'F12': '
.custom1 {
background-color: #f5e9dc;
padding: 10px;
border-radius: 10px;
font-family: sans-serif;
font-size: 0.9em;
margin-top: 1em;
}
.custom2 .style8-rw {
font-family: sans-serif;
font-weight: bold;
color: #F57215;
}'},
'sequence': ['F01',
'F02',
'F03',
'F04',
'F05',
'F06',
'F07',
'F08',
'F09',
'F10',
'F11',
'F12']}
>>> import sys
>>> sys.getsizeof(data)
136
>>> sys.getsizeof(data["sequence"])
80
>>> sys.getsizeof(data["lookup"])
520
>>>
I can not get how nested dictionary is store in memory because size if data
is 136 bytes and size of data["sequence"]
is 80 bytes and also size of data["lookup"]
is 520 bytes.
Also when I do type casting of variable data from dictionary
to string
then size of string variable is 3587 bytes
.
Demo Code:
>>> data_str = str(data)
>>> sys.getsizeof(data_str)
3587
Can any on explain me why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…