# It's dangerous - help?

#1

It's dangerous.
I'm not sure what I'm doing wrong. I thought this is how you remove a key?

Also what exactly is the difference between using '( )' and '[ ]' and also "" and '' ?

Traceback (most recent call last):
File "python", line 19, in
KeyError: 'dagger'

Solve

``````inventory = {
'gold' : 500,
'pouch' : ['flint', 'twine', 'gemstone'], # Assigned a new list to 'pouch' key
}

# 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['pocket'] = ['gold', 'pouch', 'backpack']

inventory['backpack'].sort()

inventory['dagger'].remove

inventory['gold'] = 550``````

#2

In the case of this exercise,
() - is usually used with a method, like sort, remove, append and then, insert an argument/parameter in them.
[] - to target a key in a dictionary and maybe assign a value to it.
" " and ' ' - are considered string literals. So, whatever you put in them, becomes a string -- even if a number as in maths.

Here!

Instruction 04 says:

04 Then .remove('dagger') from the list of items stored under the 'backpack' key

Which will mean

``inventory['backpack'].remove('dagger')``

Remove is a method and you need to target the dagger value of the backpack key in that dictionary.

Finally, you added 50 to the value of the gold key quite manually here.

Kindly consider doing:

``inventory['gold'] += 50``

or by interpretation:

``inventory['gold'] = inventory['gold'] + 50``

I hope this helps!

#3

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