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

David Bouchare
David Bouchare
9,224 Points

[Python collections] extend function challenge

Hi everyone,

I am having issue with the above code challenge, Python collection, challenge 3, where you have to extend a list with the numbers from 1 through 20.

Here is what I have written:

temp_list = []
for i in range(1, 20):
  temp_list.append(i)

the_list.extend(temp_list)

And the error is:

"Oops! It looks like Task 1 is no longer passing."

I am sure this is wrong given that I might extend a list with another list, but I don't really know how to solve this issue. Any feedback will be appreciated, thanks in advance!

David

4 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Why use a for loop? You already have the_list and you already have .extend(), which you can pass a range() to.

Also, remember that the_list should have [1, 2, 3] in it already. You want it to go up to 20, so where do you start the range at?

David Bouchare
David Bouchare
9,224 Points

Starting at 4 that's right.

I tried:

the_list.extend(range(4, 21))

And that worked!

Thanks a lot!

Im on this same challenge and this code isn't working for me. And its the same the same that I came up with.

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

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