find top 3 words in text file

代码如下

from collections import Counter

word_counts = Counter()
with open('1.txt', 'r') as f:
     for line in f:
          word_counts.update(line.strip().split(" "))

for key, value in (word_counts.most_common(3)):
     print (key, ':', value)
原文地址:https://www.cnblogs.com/otfsenter/p/6528489.html