Oops, try again. Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: 'dict' object has no attribute 'sort'


#1



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


Your code threw the following error: 'dict' object has no attribute 'sort'. Can you check my code?


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


#2

As it says. A dict has no attribute name sort. A dictionary also cannot be sorted, which explains why it doesn't have a method for doing so.

The question then is what you were trying to accomplish. Perhaps you meant to do something else or perhaps you need another data type, one that represents order.


#3

how do you sort what is in 'backpack'?


#4

You would obtain a reference to that value and then call its sort method.


#5

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