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 trialellie adam
26,377 PointsUse the.remove() method to remove the last item from the list.
Q;Ugh, I made this list and now it has some invalid pieces in it. Maybe you can help me clean it up. Use the .remove() method to remove the last item from the list, please.
I am trying to remove last item from list. But get this error Bummer! TypeError: remove() takes exactly one argument (0 given)
states = [
'ACTIVE',
['red', 'green', 'blue'],
'CANCELLED',
'FINISHED',
5,
]
list.remove([5])
thx
8 Answers
Seth Kroger
56,413 PointsFirst the list you want to work on is called states, not list. You should always use the specific list you want to work on when calling a method. Second, since 5 isn't a list inside the list, you don't need the square brackets. remove( [5] ) means to remove a list with a single element of 5. What you want to write is:
states.remove(5)
james white
78,399 PointsThat wasn't the complete code needed.
To get through both parts of the challeneg would require some code like:
states = [
'ACTIVE',
['red', 'green', 'blue'],
'CANCELLED',
'FINISHED',
5,
]
states.remove(5)
states.remove(['red', 'green', 'blue'])
Ali Mahmood
6,704 PointsDo spaces matter? I had a pace after remove and it wouldn't accept the answer but in workspaces I can have as much as as I want after the .remove
Daniel Dsouza
703 PointsWhy is it that when you get the closing bracket with the 5, the GUI throws an error as such : "Don't modify states directly!"
states = [ 'ACTIVE', ['red', 'green', 'blue'], 'CANCELLED', 'FINISHED', 5,] \ This is the line that I changed. I simply deleted the empty spaces. states.remove(5)
Ary de Oliveira
28,298 PointsChallenge Task 1 of 2
Ugh, I made this list and now it has some invalid pieces in it. Maybe you can help me clean it up. Use the .remove() method to remove the last item from the list, please.
states = [ 'ACTIVE', ['red', 'green', 'blue'], 'CANCELLED', 'FINISHED', 5, ]
states.remove(5)
HIDAYATULLAH ARGHANDABI
21,058 Pointslist.remove([5])
HIDAYATULLAH ARGHANDABI
21,058 Pointsstates.remove(5) is true
HIDAYATULLAH ARGHANDABI
21,058 Pointsstates = [ 'ACTIVE', ['red', 'green', 'blue'], 'CANCELLED', 'FINISHED', 5, ]
states.remove(5) states.remove(['red', 'green', 'blue'])
ellie adam
26,377 PointsThanks, Yes! I tried states before but was getting error because of []. Error was keep saying list.remove so I tried list :) Thanks again
Carlos Rivero
1,403 PointsCarlos Rivero
1,403 PointsBummer! Don't change
states
directly!lists.py
states = [ 'ACTIVE',['red', 'green', 'blue'],'CANCELLED','FINISHED', 5,]
states.remove(5)