I have a list of key/value pairs
I'd like to count unique values in pairs
example of list
[(12, 0), (10, 1), (11, 777), (11, 0) ,(10, 1)]
result something like :
[(12, 0, 1), (10, 1 , 2), (11, 777, 1), (11, 0, 1)]
I tried map operations , but didn't succeed Thanks !
Using collections.Counter:
>>> from collections import Counter
>>>
>>> lst = [(12, 0), (10, 1), (11, 777), (11, 0) ,(10, 1)]
>>> [key + (cnt,) for key, cnt in Counter(lst).items()]
[(11, 0, 1), (11, 777, 1), (10, 1, 2), (12, 0, 1)]
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