Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Why does states.remove([5]) NOT work? Error said '5' was not in a list, but I thought that states was one big list bc []

The question pertains to task 1 of 2 (the one preceding the current state)

To clarify my question, I'm asking if states is a variable (type = list), with another list inside it. If so, why do I not put colons in the .remove() funciton? Thanks.

states = [
    ['red', 'green', 'blue'],

2 Answers

Chris Freeman
Chris Freeman
Treehouse Moderator 67,989 Points

The argument to the remove() method is an object that is compared to each object in the states list and the first matching object is removed. Using a colon is part of the slice notation and isn't applicable here.

Thanks Chris and Steven! What would happen if there were several 5s in a long list and you called my_list.remove(5) ?

Steven Parker
Steven Parker
216,083 Points

It would remove the first one.

Steven Parker
Steven Parker
216,083 Points

:white_check_mark: The way you have it in the included lists.py code block is correct.

That should pass the challenge. The remove method takes the content of the item you want removed as its argument.

:point_right: The error results from putting the [5] in brackets, as in the question title.