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 (Retired) Lists Redux Manipulating Lists

David Kan
David Kan
4,058 Points

Python Collection Challenge Task 2 out of 3

Based on the instructions, I'm tasked to use the .remove() and/or del to remove the string, boolean, and list members of the_list. I'm not sure what I'm doing wrong I keep getting the "Oops! It looks like Task 1 is no longer passing". Am I not reading the question correctly? Because I'm removing "a", False, and [1, 2, 3] using both remove() and del.

the_list = ["a", 2, 3, 1, False, [1, 2, 3]]

# Your code goes below here

the_list.remove("a")

del the_list[3]

the_list.remove([1, 2, 3])

the_list

The result is [2, 3, 1]

Looking for guidance.

8 Answers

Hi David,

There isn't anything wrong with your del and remove statements but it looks like you removed the code from task 1.

You usually need to keep your previous code in place when going to the next task.

The result you should have at this point is [1, 2, 3] because in task 1 you move the 1 to the front and in task 2 you remove everything that's not a number.

the_list = ["a", 2, 3, 1, False, [1, 2, 3]]

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

the_list.remove("a")

del the_list[3]

the_list.remove([1, 2, 3])

this was my answer to the problem, I'm sure it could be cleaner:

the_list = ["a", 2, 3, 1, False, [1, 2, 3]]

# Your code goes below here
the_list.insert(0, the_list.pop(the_list.index(1)))

the_list.remove("a")

del the_list[3]

the_list.remove([1, 2, 3])
Tony McCabe
Tony McCabe
4,889 Points

Ellie Adam has the answer... These people in their questions. it would take a genius and serious algorithms to figure some of their problems.

This is my answer for steps 1 & 2. Step 1 can be done with one line because .insert will accept two arguments.

the_list.insert(0, the_list.pop(3)) the_list.remove("a") del the_list[3] the_list.remove([1, 2, 3])

the_list = ["a", 2, 3, 1, False, [1, 2, 3]]

Your code goes below here

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

the_list.remove("a")

del the_list[3]

the_list.remove([1, 2, 3])

It worked after I figured out that del requires square brackets instead of parentheses :)

Andrew Merrick
Andrew Merrick
20,151 Points

It's not a best practice but you can also repeat the del the_list[3] twice:

the_list = ["a", 2, 3, 1, False, [1, 2, 3]]

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

the_list.remove("a")

del the_list[3]

del the_list[3]
Julia Utenkova
Julia Utenkova
12,024 Points

Hi everybody!

I have come up with a slightly different solution:

the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
the_list.insert(0, the_list.pop(3))

the_new_list = []

for item in the_list:
    if type(item) == int:
        the_new_list.append(item)

print("Final List: ", the_new_list)

I know, this is not a part of a task, but it does the same functionality :)

Cheers!