It’s Dangerous to go alone! Take This: What is wrong?


#1



I have no idea what is wrong with my code. Please, help me!!!
I have an error:


Traceback (most recent call last):
File "python", line 17, in
TypeError: list indices must be integers, not str


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['backpack'].sort()
inventory['backpack'].remove('dagger')
inventory['gold'] += 50
inventory = ['pocket']
inventory['pocket'] = ['seashell', 'strange berry', 'lint']


#2

why do you have this line:

inventory = ['pocket']

i recommend to remove it, you need the key + value (which is a list) in one go, which you did here:

inventory['pocket'] = ['seashell', 'strange berry', 'lint']

which makes this line:

inventory = ['pocket']

unnecessary, in fact, it is what causes the error. in fact, it is far worse. this line:

inventory = ['pocket']

will overwrite your entire dictionary. you can see it happening:

print inventory
inventory = ['pocket']
print inventory

#3

Oh, thanks a lot!
So stupid mistake...