Here is an example where things to add come from a dictionary
>>> L = [0, 0, 0, 0] >>> things_to_add = ({'idx':1, 'amount': 1}, {'idx': 2, 'amount': 1}) >>> for item in things_to_add: ... L[item['idx']] += item['amount'] ... >>> L [0, 1, 1, 0]
Here is an example of adding items from another list
>>> L = [0, 0, 0, 0] >>> things_to_add = [0, 1, 1, 0] >>> for idx, amount in enumerate(things_to_add): ... L[idx] += amount ... >>> L [0, 1, 1, 0]
You can also achieve the above with list comprehension and zip
L[:] = [sum(i) for i in zip(L, things_to_add)]
Here is an example of adding from the list of tuples
>>> things_to_add = [(1, 1), (2, 1)] >>> for idx, amount in things_to_add: ... L[idx] += amount ... >>> L [0, 1, 1, 0]