【发布时间】:2015-09-17 10:56:04
【问题描述】:
我需要在字典上使用 for 循环来显示所有对应的值
shops = {
'Starbucks': {
'type':'Shops & Restaurants',
'location':'Track 19'
},
'Supply-Store': {
'type':'Services',
'location':'Central Station'
}
}
for shop in shops:
print(shop + " is a: " +shop.items(0))
我希望我的 for 循环做的是一次取一个项目,然后获取相应的类型和位置。现在,我一直在获取相应的类型和位置。
预期输出为:
Starbucks is a Shops & Restaurants located at Track 19.
Supply-Store is a Services located at Central Station.
【问题讨论】:
标签: python for-loop dictionary