No '.remove'?


#1



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

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


Get error: Traceback (most recent call last):
File "python", line 16, in
AttributeError: 'dict' object has no attribute 'remove'


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.remove('dagger')
inventory.append['gold'] = [50]


#2

@richardwrouse: If you want to remove "dagger" , who's inside a list who's inside a dictionary entry, you'll need to tell your program at which key/value pair it should access, like this:

inventory['backpack'].remove('dagger')
# this is what the code above means: 
# dictionary_name[key].remove(position_on_the_list)

Hope it helps! :sunny:


#4

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