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 trialParvinder Grewal
3,678 PointsHow 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
Jason Whitaker
12,252 PointsNo need to create a separate list to add 4 to 20 to the_list. Just do:
the_list.extend(range(4, 21))
Parvinder Grewal
3,678 PointsHello 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
3,678 Pointsthe_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)
print(the_list)
This is a newer iteration