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 trialPaul Conlan
577 PointsI cannot .remove the last item in list is the 5 and there are extra brackets that don’t match but keep getting arguments
Help
states = ['ACTIVE','red', 'green', 'blue','CANCELLED','FINISHED', 5]
states.remove(5)
3 Answers
Oszkár Fehér
Treehouse Project ReviewerHi 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
22,457 PointsThe 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])
Unsubscribed User
268 Pointsso why wasn't this mentioned in the video?
Sigurd Melsom
6,107 PointsYou 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