I have a list that looks like this:
(151258350, 2464) (151258350, 56) (151262958, 56) (151258350, 56) (151262958, 112) (151262958, 112) (151259627, 56) (151262958, 112) (151262958, 56)
And I want to get a result that looks like this:
151259627 56 151262958 448 151258350 2576
And here is my code:
for key, vals in d.items(): tempList.append((key, reduce(add, vals)))
here, d is a list with a key-value pair. tempList is a list in which values ββwill be added after summing them by key. and add fuction:
def add(x, y): return x+y
If this question has already been asked, please indicate there, because I could not find it myself.
source share