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 trialAhmed Elsawey
Courses Plus Student 3,527 Pointstask 2 manipulating lists redux I cant do it
Whenever I try to delete all members of the list it says task 1 is no longer passing Kenneth Love Ricky Catron
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
# Your code goes below here
num = the_list.pop(3)
the_list.insert(0,num)
del the_list[1]
del the_list[4]
del the_list[2]
del the_list[5]
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsThe tricky aspect of using del the_list[index]
is the resultant list has items at new indexes. Using your list of del
statements, there is no longer an item at index 5 by the time del the_list[5]
executes. One strategy using del
is to work from the back of the list so the item index values don't change for the closer items.
Change your ordering to this:
del the_list[5] # remove list
del the_list[4] # remove Boolean
del the_list[1] # remove string
#del the_list[2] # <-- This del not needed
Ahmed Elsawey
Courses Plus Student 3,527 PointsPlease check my other question I tagged you in it
Ahmed Elsawey
Courses Plus Student 3,527 PointsAhmed Elsawey
Courses Plus Student 3,527 PointsJason Anello chris freeman