from collections import Countera = [1, 2, 3, 1, 1, 2]result = Counter(a)print result 输出: {1: 3, 2: 2, 3: 1}