Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (2015) Python Data Types list.remove()

Alex Durham
PLUS
Alex Durham
Courses Plus Student 456 Points

how do i take an item out of a list

im not sure what i am doing wrong can anyone help?

lists.py
states = [
    'ACTIVE',
    ['red', 'green', 'blue'],
    'CANCELLED',
    'FINISHED',
    5,
]
states.remove ('blue')

1 Answer

You are trying to remove an item with the value "blue", but that value doesn't appear inside the list. I know it appears in the list that's in the outer list, but Python's remove() method doesn't check that deep.

Even if Python does check the values inside the list's lists, it will only remove that one value, and the challenge wanted you to remove the whole list from the outer list.

So, You can either write this:

states.remove(['red', 'green', 'blue'])
OR

You can write this:

del states[1]

As you see, in the second code snippet, it's a little shorter. I prefer this way, but either way will do.