https://www.cnblogs.com/herbert/archive/2013/01/09/2852843.html
>>> import collections >>> d = collections.defaultdict(int) >>> for k in s: ... d[k] += 1 ... >>> >>> d defaultdict(<type 'int'>, {'i': 4, 'p': 2, 's': 4, 'm': 1})