This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inventory = {'gold coin': 42, 'rope': 1} | |
| addedItems = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby'] | |
| for item in addedItems: | |
| if item in inventory: | |
| inventory[item] += 1 | |
| else: | |
| inventory[item] = 1 | |
| print(inventory) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def addToInventory(inventory, addedItems): | |
| for item in addedItems: | |
| inventory = inventory.get(item, 0) + 1 | |
| print(inventory) | |
| inv = {'gold coin': 42, 'rope': 1} | |
| dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby'] | |
| addToInventory(inv, dragonLoot) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def addToInventory(inventory, addedItems): | |
| for item in addedItems: | |
| inventory[item] = inventory.get(item, 0) + 1 | |
| print(inventory) | |
| inv = {'gold coin': 42, 'rope': 1} | |
| dragonLoot = ['gold coin', 'dagger', 'gold coin', 'gold coin', 'ruby'] | |
| addToInventory(inv, dragonLoot) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def addToInventory(inventory, addedItems): | |
| for item in addedItems: | |
| #Add dragonLoot to inv | |
| print(inventory) | |
| inv = {'gold coin': 42, 'rope': 1} | |
| dragonLoot = { 'gold coin' : 3, 'dagger' : 1, 'ruby' '1' } | |
| inv = addToInventory(inv, dragonLoot) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def append_twice_okay(a_list, val): | |
| """mutates argument.""" | |
| a_list.append(val) | |
| a_list.append(val) | |
| def append_twice_good(a_list, val): | |
| """returns new list.""" | |
| return a_list + [val, val] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inv = {'gold coin':42, 'rope':1} | |
| dragonLoot = {'gold coin' : 3, 'dagger' : 1, 'ruby' : 1} | |
| def add_to_inventory(inventory, added_items): | |
| for item in (added_items): | |
| #code goes here | |
| print(inventory) | |
| add_to_inventory(inv, dragonLoot) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inv = {'gold coin':42, 'rope':1} | |
| dragonLoot = {'gold coin' : 3, 'dagger' : 1, 'ruby' : 1} | |
| def add_to_inventory(inventory, added_items): | |
| for item in (added_items): | |
| inventory.update(item) | |
| print(inventory) | |
| add_to_inventory(inv, dragonLoot) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inv = {'gold coin':42, 'rope':1} | |
| dragonLoot = {'gold coin' : 3, 'dagger' : 1, 'ruby' : 1} | |
| def add_to_inventory(inventory, added_items): | |
| inventory.update(added_items) | |
| print(inventory) | |
| add_to_inventory(inv, dragonLoot) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inv = {'gold coin':42, 'rope':1} | |
| dragonLoot = {'gold coin' : 3, 'dagger' : 1, 'ruby' : 1} | |
| def add_to_inventory(inventory, added_items): | |
| inventory = dict(list(inventory.items()) + list(dragonLoot.items())) | |
| print(inventory) | |
| add_to_inventory(inv, dragonLoot) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inv = {'gold coin':42, 'rope':1} | |
| dragonLoot = {'gold coin' : 3, 'dagger' : 1, 'ruby' : 1} | |
| def add_to_inventory(inventory, added_items): | |
| for item in added_items: | |
| inventory[item] = inventory.get(item, 0) + 1 | |
| print(inventory) | |
| add_to_inventory(inv, dragonLoot) |