I got a list which is built up like this:
item_list = [
[ObjectB, 9],
[ObjectA, 2],
[ObjectB, 5],
[ObjectC, 8],
[ObjectA, 7]
]
As you can see ObjectA and ObjectB are two times in this list. The left column defines which kind of item it is, the right how often I need it. Therefore I'd like to get a result like this:
item_list = [
[ObjectB, 14],
[ObjectA, 9],
[ObjectC, 8],
]
[ObjectB, 9] and [ObjectB, 5] got merged together to [ObjectB, 14] and so did the ObjectA occurrences.
What is the best way to achieve this? I tried several solutions but I feel like there's an really easy and efficient one.