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 Collections (2016, retired 2019) Lists Removing items from a list

Richard Cairns
Richard Cairns
1,736 Points

Having trouble with Task 2/2 in the Python Collections course

I have to write code to remove the non-integer items from the list.

My code is failing with the message "It looks like Task 1 is no longer passing".

I haven't changed the code for Task 1 at all - it passed previously. I don't understand why the subsequent code would change the pass / fail for Task 1.

lists.py
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]

# Your code goes below here
messy_list.insert(0, messy_list.pop(3))

messy_list.remove("a")
messy_list.remove(False)
messy_list.remove[1,2,3]
Richard Cairns
Richard Cairns
1,736 Points

Sorry - just to be clear, the line:

messy_list.insert(0, messy_list.pop(3))

Was the solution to Task 1. The three subsequent lines are my solution to Task 2 (this task) which is to remove all of the non-integers.

I submitted the answer iteratively after adding each of these lines, one at a time, to see what the error messages would be:

messy_list.remove("a")

Result: failed because I hadn't removed all the non-integer elements (which is what I expected).

messy_list.remove(False)

Result: failed because I hadn't removed all the non-integer elements (which is what I expected).

messy_list.remove[1,2,3]

Result: failed because Task 1 was no longer passing.

1 Answer

The problem was with this line:

messy_list.remove[1,2,3]

You had forgot to put brackets around the array that you are trying to remove from the array so it didn't work. It should look like this

messy_list.remove([1,2,3])
Richard Cairns
Richard Cairns
1,736 Points

Hi Connor,

Thank you so much! I've corrected that now and it worked.

I'm still a bit perplexed as to why the error message said that Task 1 was no longer passing, but I'm just happy to be able to progress. :-)