python 统计单词个数---从文件读取版本---不去重
#/usr//bin/envpytnon#coding:utf-8
import re
'''
words = 'hello worda@r3143##### ##$dfabpple# apple##%#$3423421apple \
apple323423 432422324##apple@@#@@@@@$$!!#!#'
'''
#编译生成正则表达式对象
regexp = re.compile(r'{2,}')
#with open('./aa.txt')as f:
f = open('./aa.txt')
line = f.readlines()
print len(line)
j = 0
sum = 0
for i in range(len(line)):
j = len(regexp.findall(line))
sum = sum + j
print sum
页:
[1]