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

Warren Chisasa
Warren Chisasa
3,731 Points

The use of '.remove()' and del function

I asked this question last time but I guess I was vague because my code was undocumented. But I trying to remove the string, the boolean and the list of numbers at the last index, [1,2,3]. However, the code isn't still working. Any help please.

lists.py
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
the_list.pop(0)#pop out the string 'a'
the_list.insert(0, the_list.pop(2))#move 1 to position zero
the_list.remove('a')#remove the string
the_list.remove(False)#Remove boolean
del the_list [-1]#Remove the list members [1,2,3] at the last index

# Your code goes below here

1 Answer

David Bath
David Bath
25,940 Points

Are you just trying to pass the challenge? If that's the case then I don't know why your first line is there (popping out "a") - you do that as part of the next line, where you pop and re-insert the "a" in one step (except you have the index wrong).

Warren Chisasa
Warren Chisasa
3,731 Points

Hi David, Yes, that's the order of the task. I should first pop the string then I should remove it from the list. But the problem is that the code is wrong, I want to find out if that's how I should use the pop and remove function.

Thanks!

David Bath
David Bath
25,940 Points

Sorry for the delayed response... The instructions for the first step is: "Move the 1 to position 0. You can do this in one step with .pop() and .insert()." You are doing that with your second line:

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

Except that the index you pass to pop should be 3. Also, your first line shouldn't pop out the "a" string because that is part of step 2 of the challenge, and you are doing that with your "remove" statement.