Given:
[['x','a'], ['y','b'], ['z','a']]
I would like a list of the elements and a count frequency of the 2nd element:
[['x','a',2], ['y','b',1], ['z','a',2]]
>>> from collections import Counter
>>> L = [['x','a'], ['y','b'], ['z','a']]
>>> freq = Counter(y for x, y in L)
>>> [[x, y, freq[y]] for x, y in L]
[['x', 'a', 2], ['y', 'b', 1], ['z', 'a', 2]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With