Given the dictionary,
nested_d
, save the medal count for the USA from all three Olympics in the dictionary to the list US_countnested_d = {'Beijing':{'China':51, 'USA':36, 'Russia':22, 'Great Britain':19}, 'London':{'USA':46, 'China':38, 'Great Britain':29, 'Russia':22}, 'Rio':{'USA':35, 'Great Britain':22, 'China':20, 'Germany':13}}
US_count = []
for nested in nested_d:
# print(nested)
for country in nested_d[nested]:
if "USA" in country:
US_count.append(country)
print(US_count)
我期望输出[35,36,46]
,但实际输出是['USA', 'USA', 'USA']
请帮我解决这个问题
输出
^{pr2}$你也可以试试这个:
输出:
^{pr2}$您应该附加
nested_d[nested][country]
以获取值。在相关问题 更多 >
编程相关推荐