学习python艰辛的方式练习40帮助
发布于 2021-01-29 16:16:55
大家好,我在理解这一点时遇到了麻烦,当地图实际引用城市指令时,我不明白。还是最后一行,(城市,州)部分是什么?
谢谢。
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
关注者
0
被浏览
52
1 个回答