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

Paul Conlan
Paul Conlan
577 Points

I cannot .remove the last item in list is the 5 and there are extra brackets that don’t match but keep getting arguments

Help

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

3 Answers

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

Hi Paul. Your statement working fine, but you shouldn't change the original list. In the quiz it's a list which look like this:

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

There is a list in the list! I tried your code with this list, what the quiz gives and it pass. Happy coding

Dan Garrison
Dan Garrison
22,457 Points

The challenge is asking you to only remove the last item on the list, which you can do by using the index. Now, you could count starting at 0 and determine which index the last item is. Or you could use -1 as the index as this will always give you the last item on the list regardless of how many items are on it or what the item is.

So your code would look something like this:

states.remove(states[-1])

so why wasn't this mentioned in the video?

Sigurd Melsom
Sigurd Melsom
6,107 Points

You should remove the last element of the list. You can do it by:

states.remove( states[-1] )     # states[-1] gives the value of the last element