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

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

3 Answers

Oszkár Fehér
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 = [
    ['red', 'green', 'blue'],

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,438 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:


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