Python Lists and Dictionaries// Dictionaries


#1

Please review my code and let me know what I am doing wrong. I get the error message saying I deleted the 'inventory' dictionary.

inventory = {
    'gold' : 500,
    'pouch' : ['flint', 'twine', 'gemstone'], # Assigned a new list to 'pouch' key
    'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']
}
inventory['pocket'] : ['seashell', 'strange berry', 'lint']
# 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['backpack'].sort
inventory['gold'] = 50

#2

i can't find the exercise, can you provide the exercise url?

here:

inventory['pocket'] : ['seashell', 'strange berry', 'lint']
# Adding a key 'burlap bag' and assigning a list to it
inventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth']

you do the same thing, but one time you decide to use a colon, the other time an equal sign, which one is the right syntax?

same here:

inventory['pouch'].sort() 
inventory['backpack'].sort

one time sort has parentheses, the other time it doesn't, again, which one is it?


#3

Here is the url for the exercise I am on. Thank you for your help!

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


#4

can i also seen updated version of your code? So i can see what changes you made based on my suggestions


#5

Sure. I have made multiple changes to my code to make it to the specifications the course is asking. This is the finished code that the course said is correct.

inventory = {
    'gold' : 550,
    'pouch' : ['flint', 'twine', 'gemstone'], # Assigned a new list to 'pouch' key
    'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']
}
inventory['pocket'] = ['seashell', 'strange berry', 'lint']
# Adding a key 'burlap bag' and assigning a list to it
inventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth']
inventory['backpack'].remove('dagger')
# Sorting the list found under the key 'pouch'
inventory['pouch'].sort() 
inventory['backpack'].sort()
print inventory

#6

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