-
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(' ')
-
for i in str1:
-
if i not in words_dict:
-
words_dict[i] = 1
-
else:
-
words_dict[i] = words_dict[i] + 1
-
-
for k, v in words_dict.items():
-
print k, v
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/20747382/viewspace-2135473/
,如需转载,请注明出处,否则将追究法律责任。