练习1:
test.txt中不同元素由空格分开,写脚本允许用户输入某元素,如果该元素在文本中,输出元素个数;否则输出not found
答案:
d = {} for i in open('test.txt','r').read().split(): d[i] = d.get(i,0) + 1 k = raw_input('please input string you want :') print d.get(k,'Not Found')