Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Matt Hoang1,517 Points
Removing a single value from a list in a list
Is it possible to remove an individual item from a list that is contained inside of a list?
For example, what if I had a list named my_list and set it equal to [1, 2, 3, [4, 5]]. It is possible to remove only the 4 or the 5? When I try to input a command such as my_list.remove(), it gives me the error: ValueError: list.remove(x): x not in list.
You would first have to access that interior list and then you could call the remove method on that list, passing in whichever value you wanted to remove.
That interior list is at index 3 within the outer list.
So you could access it with:
Then you can call the remove method on that.