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()

Lisa Pitts
Lisa Pitts
3,249 Points

Remove item from list

On the Challenge Task in the 'making lists' section on Python Basics, I can't seem to remove an item. Here's the code: states = [ 'ACTIVE', ['red', 'green', 'blue'], 'CANCELLED', 'FINISHED', 5, ]

It wants me to remove the last item from the list, so I tried this: states.remove('blue') and get the error message ValueError:list.remove(x): x is not in list

I tried taking out the apostrophes and doing states.remove(blue) and get the error that blue is not defined.

Help please! And where in the code would this remove line go?

Thank you!

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

1 Answer

Russell Sawyer
seal-mask
.a{fill-rule:evenodd;}techdegree
Russell Sawyer
Front End Web Development Techdegree Student 15,705 Points

Hi Lisa,

Blue is the last item of the list INSIDE the list. The last item of the list is 5. :)

states = [
    'ACTIVE',
    ['red', 'green', 'blue'],
    'CANCELLED',
    'FINISHED',
    5,
]
states.remove(5)
Lisa Pitts
Lisa Pitts
3,249 Points

Thank you! I thought only the colors were part of the list. Makes more sense now!