今天写了一道python字典题目,用了上次字典(2)中的方法,代码如下:
json = {'totalCount':'', 'ID':'', 'IP':'10.0.0.1'} def find_value(themap, word):
if word in themap:
return themap[word]
else:
return "Not found." json['_find'] = find_value while True:
print "resule",
word = raw_input("> ")
if not word: break number_found = json['_find'](json,word)
print number_found
写完怎么运行都不对,都是显示如下:
就是不出结果,只会一直输入。
错误原因:最后两句应该在循环里面,因为 每输入一次都运行def函数在列表中找对应的number。