It's Dangerous to go alone error


#1



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


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

The error I'm getting:

File "python", line 4
'pocket' : ['seashell', 'strange berry', 'lint']
^
SyntaxError: invalid syntax

The carrot ^ under pocket is actually supposed to be directly under the ' after berry.

Not sure what the error is. I've deleted that string while troubleshooting and the error just moves. I also deleted the entire pocket key, still get an error.

Any thoughts?


#2

Missing comma delimiters in the inventory dictionary. The error is always behind the carat. It stops when what is expected is not found. In this case, it expected a comma and instead saw 'pocket'.

We can shorten this statement with the addition assigment operator:

inventory['gold'] += 50

This helps reduce repetition and typos.


#3

It was the comma after the ] bracket. I didn't know I needed those.

Also, shorten the line you mentioned above:

inventory['gold'] += 50

Thanks mtf !