Python Beginner - How to generate a list and frequency from another list -
given:
[['x','a'], ['y','b'], ['z','a']]
i list of elements , count frequency of 2nd element:
[['x','a',2], ['y','b',1], ['z','a',2]]
>>> collections import counter >>> l = [['x','a'], ['y','b'], ['z','a']] >>> freq = counter(y x, y in l) >>> [[x, y, freq[y]] x, y in l] [['x', 'a', 2], ['y', 'b', 1], ['z', 'a', 2]]
Comments
Post a Comment