我有一个嵌套的默认字典,如下所示:
source["China"]["Beijing"] = {
"num_persons" : 1454324,
"num_cars" : 134
}
source["Greece"]["Athens"] = {
"num_persons" : 2332,
"num_cars" : 12
}
如何将上述嵌套字典转换为如下记录列表glom
:
result = [
{
'country' : 'China',
'city' : 'Beijing',
'num_persons' : 1454324,
'num_cars' : 134
},
{
'country' : 'Greece',
'city' : 'Athens',
'num_persons' : 2332,
'num_cars' : 12
}
]
我看过https://glom.readthedocs.io/en/latest/tutorial.html#data-driven-assignment,但我仍然很难过。