Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (Retired) Lists Redux Manipulating Lists

Manipulating lists Challenge task 3 of 3

For some reason, it's saying that 'the_list' doesn't have the right items in it. At the end of the code, I put 'the_list.extend(range(4, 21))'

4 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

This actually helped me find a place where I didn't test answers well enough. I've updated the code challenge so it should be more clear when this happens.

Thanks!

Sweet. Thanks for the response and speedy assistance!

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

So long as the_list only has [1, 2, 3] in it by that point, what you have above should work. Can you show me what code you currently have?

Oh! Sorry. When I did "the_list.pop(1)", I should have put '3' because that was the position of the "1". I confused it with the 'remove' method. Lol! It's all clear now :)

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

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

the_list.remove("a") the_list.remove(False) the_list.remove([1, 2, 3])

the_list.extend(range(4, 21))

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Did you run this in Workspaces or your local computer? There's a bug in how you're using .pop(). .pop() removes by index, not by value, so the_list.pop(1) gets back 2 (which is in the 1 index spot), so after your the_list.insert(0, 1), your the_list looks like [1, 'a', 3, 1, False, [1, 2, 3]].

Fix that bug and the rest of your code should work fine.

Andrew Merrick
Andrew Merrick
20,151 Points

Stephen:

the_list.extend(range(4,21) 

worked for me. I would advise to check your .pop() code and try again.