def read_file(): #生成一个读取文件的函数 result = {} with open("student.txt", "r", encoding="utf-8") as f: list1 = f.read() list2 = list1.split(" ") for word in list2: if word not in result: result[word] = 0 result[word] += 1 return result words = read_file() from collections import Counter #引入统计模块 number = Counter(words) print(number.most_common(1)) #引用模块中的函数对其中次数进行比较,输出出来的是一个