Counting letters in a string
Use the built in Counter in the collections module:

&gt;&gt;&gt; from collections import Counter
&gt;&gt;&gt; Counter('qwertyqweryyyy')
Counter({'y': 5, 'e': 2, 'q': 2, 'r': 2, 'w': 2, 't': 1})