It's dangerous to go alone- delete dagger


#1

Hey Everyone,

Anyone out there that could help?
I've tried to remove the dagger out of the inventory with the .remove command
inventory['backpack'].remove('dagger')

and with the del command (see below) and I keep on getting the same error, could anyone tell me what I am doing wrong?

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

File "python", line 16
dagger_index = inventory["backpack"].index("dagger")
^
SyntaxError: invalid syntax

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['pocket'].sort(inventory[2], inventory['pocket']

dagger_index = inventory["backpack"].index("dagger")
del inventory["backpack"][dagger_index]

inventory['gold'] += 50

print inventory

Thank You!


#2

I believe you want to remove

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

#3

Thank you! I tried, but still get same error message. Any idea what it could be?

File "python", line 16
inventory['backpack'].remove('dagger')
^
SyntaxError: invalid syntax


#4

The error is before the point where parsing has stopped. Remove the above from that line, and remove the line,

if you haven't already.


#5

You have to sort 'backpack' list, not 'pocket' list.


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.