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 trialMatt Hoang
1,517 PointsRemoving 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([2]), it gives me the error: ValueError: list.remove(x): x not in list.
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Matt,
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:
my_list[3]
Then you can call the remove method on that.
my_list[3].remove(4)