count frequency with lambda
count
function can be used in map to count a frequency Also to use
*
operator in exchange for list()
>>> a='1122345'
>>> list(map(a.count, '1234567'))
[2, 2, 1, 1, 1, 0, 0]
list(map(a.count, (1,2,3,4,6,7)))
[2, 2, 1, 1, 0, 0]
a=(1,1,2,2,3,4,5)
[*map(a.count, (1,2,3,4,5,6,7))]
>>> a='1122345'
>>> import collections
>>> collections.Counter(a)
Counter({'1': 2, '2': 2, '3': 1, '4': 1, '5': 1})
Last modified 1yr ago