I want to count the instances of X
in a list, similar to
How can I count the occurrences of a list item in Python?
but taking into account a weight for each instance.
For example,
L = [(a,4), (a,1), (b,1), (b,1)]
the function weighted_count()
should return something like
[(a,5), (b,2)]
Edited to add: my a, b will be integers.