Loop through every character in a sentence in python
Question: So I need to loop through a sentence character by character and total up the
different letters and how many times they occur. I can't think of a way of
doing the first bit (I'll do the totalling up myself I have a good enough idea
and I'd like to see if I can do it solo). I'm not top notch at Python but I
assume it'll be a

    
    
    for letter in sentence
    

but I'm not sure how to loop through each letter.


Answer: You can use the
[`Counter`](http://docs.python.org/2/library/collections.html#collections.Counter)
class from `collections` (Python 2.7+):

    
    
    >>> import collections
    >>> sentence = "asdadasdsd"
    >>> collections.Counter(sentence)
    Counter({'d': 4, 'a': 3, 's': 3})
    

You can get the counts as follows:

    
    
    >>> counts = collections.Counter(sentence)
    >>> counts['d']
    4
    

