14.It's Dangerous to Go Alone! Take This


#1

inventory["pocket"] = ["seashell","strange berry","lint"]
inventory["backpack"].sort()
inventory["backpack".remove("dagger")]
inventory["gold"] = inventory["gold"] + 50

Traceback (most recent call last):
File "python", line 15, in
KeyError: 'backpack'


#2

this line:

inventory["backpack".remove("dagger")]

you want to remove from the backpack list, which has the following syntax:

aList.remove('itemToRemove')

but given your backpack list is part of inventory dictionary, you need to do get access to the list:

inventory["backpack"]

on which you can then call remove:

inventory["backpack"].remove("dagger")

i hope you see you placed your ] wrong


#3

inventory["pocket"] = ["seashell","strange berry","lint"]
inventory["backpack"].sort()
inventory["backpack"].remove("dagger")
inventory["gold"] = inventory["gold"] + 50
it still gives me the same error


#4

that is weird, then i need to see your full code


#5

inventory = {
    'gold' : 500,
    'pouch' : ['flint', 'twine', 'gemstone'], # Assigned a new list to 'pouch' key
    'bacpack' : ['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() 

# Your code here
inventory["pocket"] = ["seashell","strange berry","lint"]
inventory["backpack"].sort()
inventory["backpack"].remove("dagger")
inventory["gold"] = inventory["gold"] + 50

Traceback (most recent call last):
File "python", line 15, in
KeyError: 'backpack'


#6

here:

'bacpack' : ['xylophone','dagger', 'bedroll','bread loaf']

you misspelled backpack


#7

Thank You for your help


#8