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
Timothy Showler
Courses Plus Student 185 PointsValueError: list.remove(x): x not in list
Ok so I am a little stuck with python .remove()
The entire code is > states = ['ACTIVE',['red', 'green', 'blue'],'CANCELLED','FINISHED',5,]
I have tried to use; states.remove(['ACTIVE','CANCELLED','FINISHED',5]) and no luck, I keep getting
ValueError: list.remove(x): x not in list -- on every attempt I make. Am I doing something wrong?
2 Answers
Joseph Holms
5,409 PointsHello Timothy, It looks like the issue you are currently facing is due to the use of brackets with the "remove" command. Please see an example listed below. In this example, is shows only the parentheses used to remove the preferred portion. Please do let me know if I can answer any additional questions.
aList = [123, 'xyz', 'zara', 'abc', 'xyz']; aList.remove('xyz');
Vlad Monea
3,394 PointsHello Timothy, list.remove() only takes one parameter. By serving it all the items you want removed as a list you hoped to circumvent that but, in reality, python sees the list you entered as an item of "states" in itself, which is not the case.
You could just try to do states = states[1] --> all that's left are the elements you didn't want removed in the first place.
Tonye Jack
Full Stack JavaScript Techdegree Student 12,469 PointsTonye Jack
Full Stack JavaScript Techdegree Student 12,469 Pointsfirst your list doesn't need a comma at the end of it and using a function remove(x) x should be and item in the list and you don't need [] brackets . remove() only takes one argument in this case your specifying 4. better to use del