how to return the top n most frequently occurring chars and their respective counts # e.g \'aaaaaabbbbcccc\', 2 should return [(\'a\', 6), (\'b\'
\'aaaaaabbbbcccc\'
2
[(\'a\', 6), (\'b\'
A little harder, but also works:
text = "abbbaaaa" dict = {} for lines in text: for char in lines: dict[char] = dict.get(char, 0) + 1 print dict