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

Kyle Mahoney
Kyle Mahoney
975 Points

states.remove(['blue']) It is saying ValueError: list.remove(x): x not in list

I can't really figure out what I'm doing wrong.

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

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

The error is correct. states does not have an element that is a list ['blue']. It does have a list with all three values ['red', 'green', 'blue']. You can remove the entire list:

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

Kyle Mahoney
Kyle Mahoney
975 Points

It is asking me to remove the last item from the list.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

The wording is tricky. The last element of the list states is 5.

Kyle Mahoney
Kyle Mahoney
975 Points

When I try 'states.remove([5])' , I recieve the same error message saying (x) is not in list.

Kyle Mahoney
Kyle Mahoney
975 Points

I figured it out, it was 5, just no [] because the value wasn't in the list.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Correct. The list [5] is not in the list. You need to remove the number 5:

states.remove(5)