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

Brian Kirk
Brian Kirk
416 Points

Removing a list within a list

Can you please tell me what I am doing wrong in the below code? Trying to move the list ['red', 'green', 'blue'] from within the larger list below. The error returned is "Task 1 is no longer working" Thanks in advance!

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

lists.py
states = [
    'ACTIVE',
    ['red', 'green', 'blue'],
    'CANCELLED',
    'FINISHED',
    5,
]
states.remove(['red', 'green', 'blue'])
Kent Γ…svang
Kent Γ…svang
18,823 Points

I think it would be easier to answer if I knew what task one is. The code you have presented here is perfectly okay for removing the list within the list.

Brian Kirk
Brian Kirk
416 Points

Great thank you!

Task 1 was removing another value, I'd inadvertently omitted that line.

3 Answers

Alex Watts
Alex Watts
8,396 Points

Hello Brian,

The first question asks you to remove the 5 from the list using .remove(). When you come to answer the second question you are still required to remove the 5 as well as the list (see code below):

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

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

As you can only pass one argument into the function .remove() you will have to write the line again to get rid of the list as well.

Hope this helps.

The code is correct, the problem though is that you deleted first .remove() function from the first problem. Keep in mind when doing these practice steps that all code needs to remain in the compiler.

Brian Kirk
Brian Kirk
416 Points

Great! Thanks guys - much appreciated.