It's Dangerous to go Alone! Having problems with gold


Okay, so I'm working on the last lesson on dictionaries, ("It's Dangerous to Go Alone! Take This") and I'm having difficulties adding 50 to the value assigned in inventory['gold']. This is what I have so far.

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'

#Adding a key 'pocket' to inventory and assigning a list to it
inventory['pocket']=['seashell','strange berry','lint']

#Sorting the ist found under the key 'backpack'

#Deleting 'dagger' from the list in the key 'backpack'
del inventory['backpack'['dagger']]

#Adding 50 to the value stored under 'gold'

Now, ideally it would return 550 for "inventory['gold']", but instead I keep getting the message "File "python", line 20, in
TypeError: string indices must be integers, not str".

What am I doing wrong? Please help!



del inventory['backpack'['dagger']]

del deletes based on index. if you want to remove based on name use .remove(), or check the hint of the lesson.

it seems the exercise wants you to use .remove(), del is not possible


Okay, so I did that but now it's saying "'str' object is not callable" in line 20 of my code, which is where I'm adding to the value of gold.



this is your code, line20 is not where you add more gold?

can i see how you implemented .remove()?


Oh my God I have no idea why I thought line 20 was where I was adding to the value of gold...I'm so sorry. I just figured it out and it's fixed now. Thank you so much for your help! Again, I'm so sorry for my confusion.


no idea why you thought that, if you ever figure that out let me know :stuck_out_tongue:

Everything good now?