1 d,l,s={},[],[] 2 l=file('test.txt').read().split() 3 for word in l: 4 d[word]=l.count(word) 5 for word, count in d.items(): 6 s.append([count, word]) 7 s.sort() 8 for count, word in s: 9 print word, count