2
rs = {
'results': [
{'addresses': [{'State': 'NY'}, {'State': 'IL'}]},
{'addresses': [{'State': 'NJ'}, {'State': 'IL'}]}
]
}
我希望得到國家的列表結果中的每個成員。目前,我用下面的代碼:
for y in rs['results']:
for x in y['addresses']:
phy_states.append(x['state'])
我想是這樣的:
phy_states = [x['state'] for x in y['addresses'] for y in rs['results']]
但我不知道該怎麼辦。上面的一行代碼不起作用,因爲局部變量y在賦值之前被引用。
'[在Y [X X [ '狀態']在RS [ '結果' Y] '解決'] ]' – thefourtheye
在狀態列表中是否允許重複? – Tonechas