I am trying to get arbitrary values from nested dictionaries, but getting an error.
My approach works for one level dict
like this:
table = [
{
"A": 157,
"B": 221,
"C": 330,
"D": 380
},
{
"A": 510,
"B": 547,
"C": 660,
"D": 780
},
{
"A": 791,
"B": 1111,
"C": 1200,
"D": 3000
},
]
from operator import itemgetter
val = 525
for dv in table:
column_B = max(val, dv['B'])
if val <= dv['B']:
column_A = (dv['A'])
column_C = dv['C']
pct = dv['D']
break
But if I nest the dicts, I get an error.
table = [
"inner":{
{ "A": 157,
"B": 221,
"C": 330,
"D": 380
},
{
"A": 510,
"B": 547,
"C": 660,
"D": 780
},
{
"A": 791,
"B": 1111,
"C": 1200,
"D": 3000
},
}
]
I get an error with above nested dict. I tried slicing, even tried reduced function but could not make it work up this point. What am I getting wrong here?
question from:
https://stackoverflow.com/questions/65873128/get-inner-nested-dictionary 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…