count = {} with open('money.txt') as lyrics: raw = lyrics.read() for c in raw: count[c] = 1 + count.get(c,0) temp = [ (f,c) for c,f in count.items() ] temp.sort() temp.reverse() for f,c in temp: print(repr(c),f)