python每日一练:0004题

第 0004 题: 任一个英文的纯文本文件,统计其中的单词出现的个数。
import re

count = 0
with open('./EnglishText.txt','r') as f:
    temp = f.readlines()
    for i in temp:
        regList = re.findall('[a-zA-Z0-9]+',i) #找出每一行中的单词数
        count += len(regList)

print("文本EnglishText.txt中单词的个数为:{0}".format(count))

猜你喜欢

转载自www.cnblogs.com/xuxiaowen1990/p/11143001.html