- lines_count = 0
- words_count = 0
- chars_count = 0
- words_dict = {}
- lines_list = []
- c1 = ['!', '?', ';', '.', ',']
- all_line = ''
- import collections
- with open('c:\invalid.txt', 'r') as f:
- for line in f:
- line = line.strip('\n')
- lines_count = lines_count + 1
- all_line=all_line+line.lower()
- # print line
- #print all_line
- for i in c1:
- all_line=all_line.replace(i,' ')
- #print all_line
- str1=all_line.split(' ')
- cnt=collections.Counter(str1)
- #print str1
- print cnt
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/20747382/viewspace-2135474/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/20747382/viewspace-2135474/