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 trial

Python Python Collections (Retired) Lists Redux Manipulating Lists

challenge 3 of 3,please help am stuck

Now, make the_list contain only the numbers 1 through 20 by using .extend().

lists.py
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]

# Your code goes below here
a_list = the_list.pop(3)

the_list.insert(0, a_list)

the_list.remove("a")

del the_list[3]


the_list.extend(range(4, 21))

3 Answers

One quick thing noticed is that you only removed "a" and deleted the False boolean. The code you posted above does not erase the List value of [1,2,3]. So your range includes that list in it which may cause errors. If you use the del method be sure to note where the items have moved to since you have del and removed others so the index location (at the start it was 5 for the list) is different after the 2 items were erased. Fix that issue and see if that solves it. if not, let me know and i can give further help.

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

# the_list.pop(3)
the_list.insert(idx, the_list.pop(3)) # am inserting what is returned by pop at idx
the_list.remove('a')
the_list.remove(False)
del the_list[len(the_list)-1] # avoid getting indexbound error hence the -1
the_list.extend(range(start_pos,end_pos)) # since you already have the other item
# start_pos the starting position 
# end_pos the ending position

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

Your code goes below here

the_list.insert(0,the_list.pop(3)) the_list.remove(False) the_list.remove("a") the_list.remove([1,2,3]) del the_list[len(the_list)-1] the_list.extend(range(1,21))

This is not working..whats is wrong??