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 trialBenji Beck
5,238 PointsHow do you correct this invalid list using .remove() method on last item of the list?
So far I've added states.remove($) in attempt to remove the last item. I'm currently receiving syntax error for "states.remove($) I've tried adding a space "states.remove ($) Where did I go wrong?
states = [
'ACTIVE',
['red', 'green', 'blue'],
'CANCELLED',
'FINISHED',
5,
]
states.remove($)
2 Answers
Scott Dunstan
12,517 Pointsremove() takes the value that you want to remove so it'd have to be:
states.remove(5)
or if you didn't know the value of the last entry, you'd have to reference it by index using:
del states[-1]
Moosa Bonomali
6,297 PointsIf you only intend to remove the last item in the list, you can use the pop() function on the list like this;
states = [
'ACTIVE',
['red', 'green', 'blue'],
'CANCELLED',
'FINISHED',
5,
]
states.pop()
Benji Beck
5,238 PointsThanks Moosa, appreciate the tip!
Benji Beck
5,238 PointsBenji Beck
5,238 PointsYikes, I thought the 5 was a dollar sign. I appreciate you taking the time to break the concept down. Thanks!