Remove a few things


#1

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


I'm stuck on this. Why can't I remove 'dagger'? I'm not sure how to use the hint: dict_name['list_key'].list_function() to convert 'backpack' into a list so I can remove 'dagger'.

Can someone please help me with how this code should look?

When I just write:
backpack = ['xylophone', 'dagger', 'tent', 'bread loaf']

backpack.remove('dagger')

I get the error: backpack has to be a list! Click Reset Code to get back to the original code.

But when I use:
Backpack = ['xylophone', 'dagger', 'tent', 'bread loaf']

backpack['dagger'].list_function()

backpack.remove('dagger')

I get this error: Traceback (most recent call last):
File "python", line 3, in
TypeError: list indices must be integers, not str


I want to convert backpack into a list so I can remove 'dagger'. But I can't seem to get it right.

Backpack = ['xylophone', 'dagger', 'tent', 'bread loaf']

backpack['dagger'].list_function()

backpack.remove('dagger')


#2

This looks right. Try refreshing the page and putting this in again.


#3

Thank you! No Idea why that was so hard to get to work haha :slight_smile:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.