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

Python Collections: Lists Redux, Manipulating Lists, Challenge 2 of 3 doesn't work?

No matter what methods I use to get the answer, I get the "Oops! It looks like Task 1 is no longer passing." This is an easy challenge, with several ways to do it. I tried iterating over the list, deleting items one by one, etc. Always seeing the message. Anybody else?

3 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Use .pop() and .insert() for the first step.

Use .remove() for the second step. You can use del, but it'll be trickier because you'll have to keep track of the indexes somewhere.

I tried that. The first step passes fine, but anything I try for step 2 throws an error that step 1 isn't passing anymore. I assume I don't modify the code entered in step 1.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Nope, don't need to modify step 1's code at all.

the_list.insert(0, the_list.pop(3))
the_list.remove('a')
the_list.remove(False)
the_list.remove([1, 2, 3])

will pass steps 1 and 2

Joshua Lawson
Joshua Lawson
4,953 Points

THANK YOU for this. I was about to have my cat take a stab at completing the challenge!

Thanks. I double-dog pinky swear I did that--but pasting in your code made it work. Ah well.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

It's all good!

I know the CC is a bit mind-mangling with having to track the state of the list. I promise that that's on purpose :)

Richard Boag
Richard Boag
5,547 Points

So the breakdown of the command reads like this?

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

Insert at place value 0

But I don't quite understand how the_list.pop(3) puts the number 1 in that place value spot. Thanks for the site, I'm loving it!

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

the_list.pop(3) finds the fourth item in the list (0, 1, 2, 3) and takes it out of the list. You could use this to put that item into a variable with something like item = the_list.pop(3) but we don't need to.

Then, when we do the the_list.insert(), we're putting the value that .pop() got back into the list.