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 trialKyle Mahoney
975 Pointsstates.remove(['blue']) It is saying ValueError: list.remove(x): x not in list
I can't really figure out what I'm doing wrong.
states = [
'ACTIVE',
['red', 'green', 'blue'],
'CANCELLED',
'FINISHED',
5,
]
states.remove('blue')
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsThe 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
975 PointsKyle Mahoney
975 PointsIt is asking me to remove the last item from the list.
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsThe wording is tricky. The last element of the list states is
5
.Kyle Mahoney
975 PointsKyle Mahoney
975 PointsWhen I try 'states.remove([5])' , I recieve the same error message saying (x) is not in list.
Kyle Mahoney
975 PointsKyle Mahoney
975 PointsI figured it out, it was 5, just no [] because the value wasn't in the list.
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsCorrect. The list
[5]
is not in the list. You need to remove the number5
:states.remove(5)