1 name = input("Enter file:") 2 if len(name) < 1 : name = "input.txt" 3 fhand = open(name) 4 5 counts = dict() 6 for line in fhand: 7 words = line.split() 8 for word in words: 9 # find the value that key is word, if not, return 0 10 counts[word] = counts.get(word, 0) + 1 11 12 lst = list() 13 for key, val in counts.items(): 14 lst.append( (val, key) ) 15 16 lst.sort(reverse = True) 17 for val, key in lst[:10]: 18 print (key, val)