【发布时间】:2015-12-23 05:19:27
【问题描述】:
我有以下代码:
voorzieningen = {
"NS-service- en verkooppunt": {"type:": "verkoop- en reisinformatie", "locatie": "spoor 11/12"},
"Starbucks": {"type": "Winkels en restaurants", "locatie": "spoor 18/19"},
"Smeulers": {"type": "Winkels en restaurants", "locatie": "spoor 5/6"},
"Kaartautomaat": {"type": "Verkoop- en reisinformatie", "locatie": "spoor 1"},
"Toilet": {"type": "Extra voorziening", "locatie": "spoor 4"}
}
def voorzieningen_op_utrecht():
for voorziening in voorzieningen:
print(voorziening)
voorzieningen_op_utrecht()
我想要得到的是以下内容:
<First value> "is of the type " <second value> "and is located at" <third value>
例如:
星巴克属于 Winkels en 餐厅类型,位于 spoor 18/19。
我希望它是一个 for 循环,以便打印所有值。
附:为荷兰人道歉,但这不应该让代码更难理解。
【问题讨论】:
-
"First", "second" 和 "third" 没有意义,字典不保证顺序.你看过
str.format吗?另外,请注意,您的其中一个键是'type:'而不是'type'。
标签: python for-loop dictionary