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

Removing list

Not sure what I am doing wrong here but I know it might be something easy.

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

5 Answers

This will remove all nested 'blue'.

for state in states:
    try:
        state.remove('blue')
    except ValueError:
        pass

I think that the method is considering the red green and blue one single item.

So did anybody got it working ? I'm stock here :/

You could try this:

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

color = states[1]
color.remove('blue')

print(states)

Can you post / link the question, as I am not sure what you are trying to achieve

I got it working already. thanks