Appending a value to a list (List and Dictionaries>Lesson 14)


#1

I am getting an error on Lesson 14: "AttributeError: 'int' object has no attribute 'append' "

I am fairly certain my code is correct, but it seems that their is an issue with how I am attempting to append the value 50 to the list "Gold".

Here is my code (the problem seems to be the last line):

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'

inventory['pouch'].sort()

Your code here

inventory['pocket'] = ['seashell', 'strange berry', 'lint']

inventory['backpack'].sort()

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

inventory['gold'].append(50)


#3

It does not work! Even tried copying and pasting - still does not work!


#4

@tortugavaldez

Your error message is

Seems cut and dry to me.

If you still do not grasp what I am getting at, an int is not a list.

To add to a value inside of a dict simply add to it, as follows

dict_of_numbers = {'first': 5, 'second': 51}
dict_of_numbers['first'] += 41

print(dict_of_numbers):
# OUTPUT: {'first': 46, 'second': 51}

Easy as pie. If you need anything else feel free to ask.