Its dangerous to go alone - remove dagger


#1


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

The error is in line 16. I cant remove dagger
Error message: Traceback (most recent call last):
File "python", line 16, in
AttributeError: 'builtin_function_or_method' object has no attribute 'remove'

I dont understand why it doesnt just remove dagger. Please help ?


nventory = {
    '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"] = inventory["backpack"].sort
inventory["backpack"].remove("dagger")
inventory["gold"] += 50


#2

the problem is actually here:

inventory["backpack"] = inventory["backpack"].sort

.sort() is a method, calling it requires parentheses. Currently you store the method itself in backpack

also, .sort() will manipulate the list directly and return None, so you shouldn't store the result in a variable, since this variable will capture the returned result (None)


#3

Thank you for your reply! So I need to change the sort part...but...how? ^^; I tried it like this:

Your code here

inventory["pocket"] = ["seashell", "strange berry", "lint"]
inventory["backpack"].remove("dagger")
inventory["backpack"].sort(inventory["backpack"])

But it says:
Traceback (most recent call last):
File "python", line 17, in
TypeError: 'list' object is not callable

Thank you a lot for your help. I'm really stuck. -_-

!!! EDIT It is working with empty parenthesis after sort :slight_smile:

Your code here

inventory["pocket"] = ["seashell", "strange berry", "lint"]
inventory["backpack"].remove("dagger")
inventory["backpack"].sort()
inventory["gold"] += 50


#4