import collections number = [0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1] collections.Counter(number) #output #Counter({0: 12, 1: 9})