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)