1# importing the collections module
2import collections
3# intializing the arr
4arr = [1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3]
5# getting the elements frequencies using Counter class
6elements_count = collections.Counter(arr)
7# printing the element and the frequency
8for key, value in elements_count.items():
9 print(f"{key}: {value}")
1sum(c.values()) # total of all counts
2c.clear() # reset all counts
3list(c) # list unique elements
4set(c) # convert to a set
5dict(c) # convert to a regular dictionary
6c.items() # convert to a list of (elem, cnt) pairs
7Counter(dict(list_of_pairs)) # convert from a list of (elem, cnt) pairs
8c.most_common()[:-n-1:-1] # n least common elements
9c += Counter() # remove zero and negative counts
10