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

Indra Bergmans
Indra Bergmans
2,199 Points

I'm struggling with the .remove in Python.

Now I have to remove the colours from the list, besides the already removed '5'. How do I do this? I have to use the code that was used to remove the '5'.

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

4 Answers

Steven Parker
Steven Parker
231,271 Points

Each remove operation will be done on a separate line.

You'll keep the line you did for task 1, but add more code under it.

Also, when removing a sub-list, remember to put the brackets [] around the list items in your argument.

Indra Bergmans
Indra Bergmans
2,199 Points

Hello Steven,

I tried doing the same I did for the first task, for the second one. I did the code under the first task, but it didn't accept it. I'm still not getting it apparently...

Steven Parker
Steven Parker
231,271 Points

Show what your revised code looks like.

Indra Bergmans
Indra Bergmans
2,199 Points

I did this:

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

Steven Parker
Steven Parker
231,271 Points

Now it just looks like you have your brackets and parentheses reversed. The list goes in the brackets [] and then all that goes inside the parentheses () that come after the method name.

Indra Bergmans
Indra Bergmans
2,199 Points

That was it! I'll probably have to repeat this part a few times to get it down. Thanks for your help Steven!