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

Alexander Alcaraz
Alexander Alcaraz
550 Points

I'm having trouble understanding what part of this list is the last part to remove.

From my logic the integer 5 is last in the list. So I used states cause variable .remove() with the [5] from the last part of the list but it's not working. Am I missing what is the last part of the list or am I formatting it incorrectly?

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

states.remove([5])

1 Answer

Hi Alexander,

You're correct that you want to remove the integer 5 from the list. So you only need to pass the value 5 to the remove method.

Your code is trying to remove a list that contains the integer 5.

You would want to do that if the states list looked like this:

states = [
    'ACTIVE',
    ['red', 'green', 'blue'],
    'CANCELLED',
    'FINISHED',
    [5],
]

Notice that the last item of the states list is no longer the integer 5 but a list containing the integer 5. Your code would be able to remove that.