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

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 68,423 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
229,005 Points

It would remove the first one.

Steven Parker
Steven Parker
229,005 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.