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 trialDimitar Tsvetkov
6,806 PointsCollection challenge. Please help. Can't make second task work. What am I doing wrong?
Please someone explain why doesn't my code work?
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
# Your code goes below here
the_list_1 = the_list.pop(3)
the_list.insert(0, the_list_1)
remove_member = [1, 4, 5]
for i in sorted(remove_member, reverse=True):
del the_list[i]
print the_list
3 Answers
Kenneth Love
Treehouse Guest Teacherprint
won't work because this is Python 3, not Python 2.
Once you ditch the "a" and move the "1", doing del the_list[1]
, which your for loop does, removes the "2". I don't think that's something you want to do.
Scale back the cleverness and just try it the long, ugly way.
Dimitar Tsvetkov
6,806 PointsI solved it. Thank you Kenneth!
andre karamanian
1,186 Pointsso this works in python 3.5 (see below) del crunches all the objects?! what up with that?! I pac-manned position 0 as the list got smaller until empty set of course this doesnt work in the challenge screen
list23b.py: cant get this to display properly in this answer box but basically for loop over range len(the_list) with del the_list[0] inside the loop, eating the list from left to right
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
print(the_list)
the_list.insert(0,the_list.pop(3))
for i in range(len(the_list)):
del the_list[0]
print(the_list)
$ python3 list23b.py
['a', 2, 3, 1, False, [1, 2, 3]]
['a', 2, 3, False, [1, 2, 3]]
[2, 3, False, [1, 2, 3]]
[3, False, [1, 2, 3]]
[False, [1, 2, 3]]
[[1, 2, 3]]
[]
Kenneth Love
Treehouse Guest TeacherI'm not sure what you're asking. Yes, del
can/will delete everything