Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python collections counter

import collections

arr = ['a', 'a', 'b', 'b', 'b', 'c']

# set the elements frequencies using Counter class
elements_count = collections.Counter(arr)

# printing the element and the frequency
for key, value in elements_count.items():
    print(f"{key}: {value}")

# output
# a: 2
# b: 3
# c: 1
Source by codefreelance.net #
 
PREVIOUS NEXT
Tagged: #python #collections #counter
ADD COMMENT
Topic
Name
7+7 =