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

ValueError

My error says list.remove(x) x is not in list but I don't understand why, everything looks correct.

lists.py
states = ['ACTIVE',['red', 'green', 'blue'],'CANCELLED','FINISHED',5] 
states.remove(['red', 'green', 'blue',5])

2 Answers

Julien riera
Julien riera
14,665 Points

Hi,

As a hint, I can tell you that you combine 2 elements of your states list, which you can't. Here you're targeting a list (the colors) + an int (5) in a single list whereas these are 2 seperated elements of your initial list "states".

So, first idea that may occur to you is writing down :

states.remove(['red', 'green', 'blue'], 5)

It seems legit, but sadly, you can't do that as the remove function only takes one argument. Here are given two.

So in this case, you may wanna use remove twice in a row, or check the Python documentation to see if there is something that suits better your needs.

states = ['ACTIVE',['red', 'green', 'blue'],'CANCELLED','FINISHED',5] 
states.remove(['red', 'green', 'blue'])
states.remove(5)

This would work as it targets one element of the list at a time, and gives only one argument per remove call.

More relevant information here : [https://docs.python.org/2/tutorial/datastructures.html]

Hope this helps !

Julien

codeoverload
codeoverload
24,260 Points

You can't remove ['red', 'green', 'blue',5], because the list doesn't exist in states. But you could remove ['red', 'green', 'blue'] (without the 5).