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 trialBob Amand
2,639 Pointsstuck on lists.py
Task 1 clears. I have been struggling with Task 2. For some reason when I make a mistake in Task 2 the system flags Task 1. Seem to be stuck in my own perpetual loop. I have attempted at least 15 alternative solutions yet no closer to completing. No longer learning.
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
# Your code goes below here
the_list.insert(0, the_list.pop(3))
for item in the_list:
if item != range(1,3):
del the_list[item]
3 Answers
Ken Alger
Treehouse TeacherBob;
Welcome to Treehouse!
I can fully relate to the frustration of being stuck on some of these challenges, but you are doing great and asking questions is key!
Let's take a look at this task in particular.
Task 2
Use
.remove()
and/ordel
to remove the string, boolean, and list members ofthe_list
.
Here is our list
after we have completed Task 1
the_list = [1, "a", 2, 3, False, [1, 2, 3]]
If you remember from the course videos we can remove things explicitly with remove()
like:
the_list.remove("some string value")
or we can delete specific index values with del
using the syntax:
del the_list[3]
which would remove the item at index 3.
I hope that gets you pointed in the right direction but please post back if you are still stuck or have further questions.
Happy coding,
Ken
Ken Alger
Treehouse TeacherBob;
Let's look at Task 2 this way...
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
the_list.insert(0, the_list.pop(3))
# Your code goes below here
Keep in mind that if you are referencing items in Task 2 using index numbers, the code from Task 1 will change the index values of the_list
for use in Task 2.
Ken
Bob Amand
2,639 PointsI moved my Task 1 code above the "# your code below..." (not sure if it should matter but seemed to!). I understand the index shift and used: del my_list[1, 4, 5] did not pass. del my_list[1] del my_list[4] del my_list[5] did not pass with an "index out of range" now trying a combination of remove/del to determine if remove only for text, etc. is the issue.
Bob Amand
2,639 PointsKen, I finally convinced the system to accept my answer. I used the_list.remove(individual values).
I had tried every permutation; del the_list[5] kept giving me an index out of range error.
Thank you for the help. I appreciate validating my Task 1 answer and the clues for Task 2.
Regards,
Bob
Ken Alger
Treehouse TeacherBob;
Way to stick with it!
Happy coding,
Ken
Bob Amand
2,639 PointsKen, Here is the code for Task 1:
the_list.insert(0, the_list.pop(3))
a second try:
my_list = the_list my_list.insert(0, my_list.pop(3))
Thanks, Bob
Ken Alger
Treehouse TeacherBob;
the_list.insert(0, the_list.pop(3))
That works. Task 2 is built upon that so don't delete that line, just remove()
or del
items with code after that line.
Ken
Bob Amand
2,639 PointsBob Amand
2,639 PointsExcellent. I think I now understand the solution for Task 2. BUT, there must be something wrong with my Task 1 answer because it claims it longer passes once I put in Task 2! Here is my code for Task 1: -to move 1 from current location in one step. First it is accepted. Add Task 2 and it is not! the_list.insert(0, the_list.pop(3))
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherBob;
Can you post the current code you are using? Sometimes the challenge checker is a bit, um, picky, yeah, let's go with picky.
Ken
Bob Amand
2,639 PointsBob Amand
2,639 PointsKen, second try: Task 1 code that passes:
the_list.insert(0, the_list.pop(3))
Task 1 doesn't pass when I attempt Task 2!
Thanks, Bob