Files
30-seconds-of-code/test/count_by/count_by.py
Rohit Tanwar 385bf72a3e readme-script
2018-02-20 22:42:11 +05:30

6 lines
161 B
Python

def count_by(arr, fn=lambda x: x):
key = {}
for el in map(fn, arr):
key[el] = 0 if not el in key else key[el]
key[el] += 1
return key