It's Dangerous to go alone error


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['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?


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.


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 !