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.
Dimitar Tsvetkov6,806 Points
Collection 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
Kenneth LoveTreehouse Guest Teacher
Once you ditch the "a" and move the "1", doing
del the_list, 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.
andre karamanian1,184 Points
so 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 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 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]]