我正在阅读 zed shaw 的书“Learning python the hard way”。原谅我,但我是编码新手,我很难理解这一点。我似乎看不到 find_city 函数如何通过输入状态找出要返回的城市。带有“好吧注意”和“#这条线是最重要的!学习!是那些让我感到困惑的线。
cities = {'CA': 'San Francisco', 'MI': 'Detroit',
'FL': 'Jacksonville'}
cities['NY'] = 'New York'
cities['OR'] = 'Portland'
def find_city(themap, state):
if state in themap:
return themap[state]
else:
return "Not found."
# ok pay attention!
cities['_find'] = find_city
while True:
print "State? (ENTER to quit)",
state = raw_input("> ")
if not state: break
# this line is the most important ever! study!
city_found = cities['_find'](cities, state)
print city_found