14. Its Dangerous to go Alone. What am I doing wrong?


#1



https://www.codecademy.com/courses/python-beginner-en-pwmb1/2/5?curriculum_id=4f89dab3d788890003000096#


Traceback (most recent call last):
File "python", line 20, in
ValueError: list.remove(x): x not in list


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() 

# Your code here
inventory = {
    'pocket' : ['seashell', 'strange berry', 'lint']
}

backpack.sort()

backpack.remove('dagger')

gold += 50


#2

backpack is part of inventory dictionary.

so you need to access the backpack inside inventory dictionary


#3

that was actually the second attempt that i tried:

inventory['backpack'].sort()

inventory['inventory'].remove('dagger')

Error still came up:

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


#4

here:

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

you overwrite your inventory dictionary, so now inventory on contains pocket


#6

but what about the rest of the code at the top that was already input. would I have to add that to my current code for it to run?


#7

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()

Your code here

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

inventory['backpack'].sort()

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

gold += 50

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


#8

look:

nventory = {
'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()

Your code here
inventory = {
'pocket' : ['seashell', 'strange berry', 'lint']
}

print inventory

You should have added pocket to inventory, instead you made pocket the only thing in inventory


#10

Thanks for the tips I got it now


#11