Its dangerous to go alone


#1

inventory = {
‘gold’ : 500,
‘pouch’ : [‘flint’, ‘twine’, ‘gemstone’], # Assigned a new list to ‘pouch’ key
’backpack’ : [‘xylophone’,‘dagger’, ‘bedroll’,‘bread loaf’]
}

Adding a key ‘burlap bag’ and assigning a list to it

inventory[‘burlap bag’] = [‘apple’, ‘small ruby’, ‘three-toed sloth’]

Sorting the list found under the key ‘pouch’

inventory[‘pouch’].sort()

inventory = {‘pocket’ : [‘seashell’, ‘strange berry’, ‘lint’]}
inventory[“backpack”].sort()
inventory[“backpack”].remove(“dagger”)

inventory[‘gold’] + 50

The error is Traceback (most recent call last): Thanks for any help!
File “python”, line 14, in
KeyError: ‘backpack’


#2

Hi @goldenmatrices,

Here, you assigned an entirely new dictionary to inventory, with only the key, 'pocket'

inventory = {‘pocket’ : [‘seashell’, ‘strange berry’, ‘lint’]}

After that, it no longer has a 'backpack' key.

Instead, add a new item with the key, 'pocket', to the existing dictionary, as follows …

inventory['pocket'] = ['seashell', 'strange berry', 'lint']

#3

Okay thank you! It works now!


#4