Can't figure out last line:) to add 50 to gold :( nothing works . #14


File "python", line 20
inventory['gold'] = inventory['gold']+50
SyntaxError: invalid syntax

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'

# Your code here
inventory['pocket'] = ['seashell', 'strange berry', 'lint']

del inventory[backpack.remove[1]
inventory['gold'] = inventory['gold']+50

Continuing the discussion from 14/14 Lists and Dictionaries HELP!:

del inventory[backpack.remove[1]

The above line is causing you problems. First of all you are missing the closing bracket ].

del inventory[backpack.remove[1]]

backpacks.remove is a method so you should instead write:

del inventory[backpack.remove(1)]

But if you want to remove the backpack key from inventory dictionary, you should write:

del inventory["backpack"]


Thanks a lot!
i thought that del inventory["backpack"] removes the whole list, no?


Yes, when you type del inventory["backpack"], you remove the "backpack" key from inventory, which automatically removes its associated value - the whole list.


Then to remove the "dagger" would be del inventory[1] or del inventory['dagger'] ?
I am confused:)
or which one?


Removing the "dagger" element from the list (associated with "backpack" key of inventory dictionary) is different from removing the "backpack" key from inventory dictionary.

Re-read the above line until it makes sense. Then move forward.

I will give you two hints on how to remove "dagger" from that list.

  1. Hint1: You need to access the list first. This is achieved by inventory["backpack"].
  2. Hint2: You need to refer to the docs (fourth heading) and figure out how .remove works :wink:


If you have a =dictionary=

inventory = {
    'gold' : 500,
    'pouch' : ['flint', 'twine', 'gemstone'], # Assigned a new list to 'pouch' key
    'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']

you have an inventory dictionary
which has 3 properties separated from eachother by a comma-,

a gold property with property-key gold and an associated number Value 500
a pouch property with property-key pouch and an associated list Value
a backpack property with property-key backpack and an associated list Value

Now if you use
you are actually accessing the associated list Value
['xylophone','dagger', 'bedroll','bread loaf']

Now if you use
you have put your finger on the 1st List-Element which has the index =zero=
['xylophone','dagger', 'bedroll','bread loaf']
being a string Value 'xylophone'

Now if you use
you have put your finger on the 2nd List-Element which has the index =one=
['xylophone','dagger', 'bedroll','bread loaf']
being a string Value 'dagger'

Thus using the del Method
del inventory['backpack'][1]
you would =delete= 'dagger' from the =list=
causing the =index-build= of the =list= to be re-calculated as
would now be the =list=
['xylophone', 'bedroll','bread loaf']
would now be the string Value 'bedroll'

== the Book ==
== discussions / opinions ==


Imagine you have 2 processes

  • one takes =action-requests= and =append='s those requests to an action-list
    action_list = [ req-1,req-2,req-3]
  • an other will =process= those =action-requests= one at a time, by picking an =action-request= fron the action-list
    You could do it with
    req_to_process = action_list.pop(0) ==> req_to_process would be req-1
    ( this is called FIFO ==> First In First Out )
    req_to_process = action_list.pop() ==> req_to_process would be req-3
    ( this is called LIFO ==> Last In First Out )