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 trialDavid Wright
4,437 PointsWhy 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 = [
'ACTIVE',
['red', 'green', 'blue'],
'CANCELLED',
'FINISHED',
5,
]
states.remove(5)
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsThe 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.
Steven Parker
231,261 PointsThe 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.
The error results from putting the [5] in brackets, as in the question title.
Chris Freeman
Treehouse Moderator 68,441 PointsNice emoji use
Steven Parker
231,261 PointsI have way too much fun with these things.
David Wright
4,437 PointsDavid Wright
4,437 PointsThanks Chris and Steven! What would happen if there were several 5s in a long list and you called my_list.remove(5) ?
Steven Parker
231,261 PointsSteven Parker
231,261 PointsIt would remove the first one.