我需要创建一个程序来分析文件中的一段文本,然后进行计数:
多少字
单词的平均长度
每个单词出现多少次
字母表中每个字母开头有多少个单词
到目前为止,我已经成功完成了前两个要点(如下所示),
fileName = open(input('Please enter the full name of the file: '), 'r')
w = [len(word) for line in fileName for word in line.rstrip().split(" ")]
total_w = len(w)
avg_w = sum(w) / total_w
print('The total number of words in this file is:', total_w)
print('The average length of the words in this file is:', avg_w)
幕布斯6054654
相关分类