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

Use 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
Seth Kroger
56,413 Points

First 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)
Carlos Rivero
Carlos Rivero
1,403 Points

Bummer! Don't change states directly!

lists.py

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

states.remove(5)

That 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
Ali Mahmood
6,704 Points

Do 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
Daniel Dsouza
703 Points

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

Challenge 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
HIDAYATULLAH ARGHANDABI
21,058 Points

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

states.remove(5) states.remove(['red', 'green', 'blue'])

Thanks, Yes! I tried states before but was getting error because of []. Error was keep saying list.remove so I tried list :) Thanks again