1、collections.Counter()方法
from collections import Counter
#直接collections.Counter(list)就可以得到list中每个元素的个数
#返回类型是collections.Counter,可以将其手动转换为dict
def get_count_by_counter(l):
count = Counter(l) #类型: <class 'collections.Counter'>
count_dict = dict(count) #类型: <type 'dict'>
return count_dict #or return count