Home > other >  Beginners, consult the list of values in the traverse to the dictionary this code why the return val
Beginners, consult the list of values in the traverse to the dictionary this code why the return val

Time:01-04

Inv={' gold coin: 42, "rope" : 1}
DragonLoot=[' gold coin ', 'gold coin', 'rope']
Def addToInventory (inventory1 addedItems) :
For p in the range (0, len (addedItems) :
If addedItems [p] not in inventory1. Keys () :
Inventory1. Setdefault (addedItems [p], 1)
The else:
Inventory1 [addedItems [p]]=inventory1 [addedItems [p]] + 1
Av=addToInventory (inv, dragonLoot)
Print (av)