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

list.remove

states = [ 'ACTIVE', ['red', 'green', 'blue'], 'CANCELLED', 'FINISHED', 5, ] states.remove(['red', 'green', 'blue'])

this doesnt work i tried on unix it works - what is the problem?

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

6 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there tanmay sharma! To remove the items from a list the code needs to be outside the definition of the states array. And we do this like so:

states = [
    'ACTIVE',
    ['red', 'green', 'blue'],
    'CANCELLED',
    'FINISHED',
    5,
]
states.remove(5)
states.remove(['red', 'green', 'blue'])

The first states.remove will remove the 5. 5 is not a string, nor is it part of an array inside of an array, so only the 5 is needed inside the parentheses. The second states.remove line needs the brackets inside the parentheses as we're removing an array from inside an array. Hope this helps! :sparkles:

tanmay sharma
tanmay sharma
267 Points

@Jennifer Nordell thanks for the help

again

states = [ 'ACTIVE', ['red', 'green', 'blue'], 'CANCELLED', 'FINISHED', 5, ] states.remove(['red', 'green', 'blue'])

henry jefferson
henry jefferson
2,136 Points

try this:

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

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

print (states)
henry jefferson
henry jefferson
2,136 Points

I think you have to perform states.remove() on a separate line. Also, it's worth noting that workspaces can be buggy. Sometimes try saving and reloading the page.

thank Henrys. what i noticed on that page where script is to be writtten GET HELP doesnt work also

tanmay sharma
tanmay sharma
267 Points

how to remove 5from that list