练习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')
练习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')
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。