c = collections.Counter(nums) code example Example: import counter python from collections import Counter