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.

Python Python Collections (Retired) Lists Redux Manipulating Lists

Parvinder Grewal
Parvinder Grewal
3,678 Points

How to replace a list with a range value.

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

Your code goes below here

temp = the_list.pop(3) the_list.insert(0,temp) del the_list[4] the_list.remove('a') del the_list[3]

the_list = the_list.extend(range(1,21))

I am not sure of how to extend a range of 1-20 to the_list.

3 Answers

No need to create a separate list to add 4 to 20 to the_list. Just do:

the_list.extend(range(4, 21))
Parvinder Grewal
Parvinder Grewal
3,678 Points

Hello Code Comrades,

I read the question more carefully and was able to pass the test. The values 1-20 have to exist in the list, since the previous lines of code leave us with 1,2,3 in the list we can extend with range(4,21) !

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

Your code goes below here

temp = the_list.pop(3) the_list.insert(0,temp) del the_list[4] print(the_list) the_list.remove('a') del the_list[3] print(the_list)

new_list = range(4,21) the_list.extend(new_list) print(the_list)

Parvinder Grewal
Parvinder Grewal
3,678 Points

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

Your code goes below here

temp = the_list.pop(3) the_list.insert(0,temp) del the_list[4] print(the_list) the_list.remove('a') print(the_list)

for i in the_list: the_list.pop(i)

new_list = range(1,20) the_list.extend(new_list)

This is a newer iteration