I am trying to write a program which updates values in a dictionary.
stuff = {'rope': 1, 'torch': 6, 'gold coin': 42, 'dagger': 1, 'arrow': 12}
dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby']
#stuff = addToInventory(stuff, dragonLoot)
for i in range(len(dragonLoot)):
for k, v in stuff.items():
if dragonLoot[i] == k:
v += 1
displayInventory(stuff)
As you can see I already moved the snippet in my main to ensure that it's not a problem with the function. The outer for-loop also works. The problem is, v
just dosen't get updated. displayInventory()
prints the same values as in the declaration at the top.
Thank you in advance for your input!