## 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!

### 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.  # Why is extend not working with range() here?

the_list.extend(range(1, 21))

• works fine in python in terminal, but not here?

I think it's including other elements like 1,2,3 in the_list. So it's duplicating instead of extending elements 4 to 20.

try

the_list.extend(range(4, 21)) STAFF

OK, let's step through it.

• Step 0: `the_list = ["a", 2, 3, 1, False, [1, 2, 3]]`
• Step 1: `the_list.insert(0, the_list.pop(3))` `the_list` is now `[1, "a", 2, 3, False, [1, 2, 3]]`
• Step 2:
```the_list.remove('a')
the_list.remove(False)
the_list.remove([1, 2, 3])
```

`the_list` is now `[1, 2, 3]`

• Step 3: Make `the_list` have all of the numbers from 1 to 20.

I'll leave the rest to you.

Here's what I came up with

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

# Your code goes below here
the_list.pop(3)
the_list.insert(0, 1)
the_list.remove([1, 2, 3])
del the_list
del the_list

the_list.extend(range(4,21))
```

Quite a mental approach I must say, but it works! STAFF

It'll `.extend()` the list with the `range()` just fine. The problem is the contents of your `the_list` before and after the `.extend()`. It should be 1-20 with each number only appearing once...what do you have? Ah, get it now!

Suggestion: Rephrase the text to "Make the list contain ONLY the numbers 1 to 20 using extend()" That would make it much clearer that it's not just a matter of making the list contain the numbers (which extend(1, 21) does), but of making sure 1-20 is all it contains.

```the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
the_list.insert(0, the_list.pop(3))  # the_list is now [1, "a", 2, 3, False, [1, 2, 3]]
the_list.remove('a')
the_list.remove(False)
the_list.remove([1, 2, 3])
the_list.extend(range(4,21))
```

these are my codes why its not working? i had already 1 2 3 in my list so i just add the rest

I was getting an error here as well

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

# Your code goes below here

the_list.insert(0, the_list.pop(3))

list=[5, 4, 1]

for numbers in list:
del the_list[numbers]

the_list.extend(range(4,21))
print(the_list)
```
```Error: Traceback (most recent call last): File "4fd7aca7-edd9-4f26-bb1e-8f7ba011333e.py", line 105, in """) File "", line 2, in TypeError: 'list' object is not callable
```

I tested the script in workspace and it works fine for me. How do you post your code so it looks like that? I tried the ''' method from the markdown cheatsheet, but it doesn't work. Any tips? My code looks exactly like you guys' but it's saying Task 1 is no longer passing.

Here's my code:

```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("a")
the_list.remove(False)
the_list.remove([1, 2, 3])
the_list.extend(range(4:21))
``` You need to use three backticks (on a US keyboard, they're to the left of the 1) to get the code block. You can follow it with a language name to get syntax highlighting.

As for why your code isn't working, you need a comma in your `range()` call, not a colon.

Is there no way to remove all items in one step? E.g. the_list.remove("a", False, [1, 2 ,3])?? I used a list comprehension to do it like this:

```the_list = [int(x) for x in the_list if str(x).isdigit()]
```

The int(x) is referring to the list item and I am casting it to an integer. For x is the iterator, in the_list is what its iterating through and the test condition is the if str(x) which is the current list item is a digit or not. If false it is not reassigned to the new list, if true it is. So this builds a new list and filters out all non numbers.

I had to use str(x) in the condition because isdigit is a string method. I used the int(x) in the start so that if there was a number being represented as a string: '2' it wouldn't be placed in the new list as a string.

I have been hanging out here: https://discord.gg/d39VM asking questions about Python and getting help. Hi Guys,

I actually figured this out by creating another list. There are better ways to do this, but it was get you past the test.

```the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
the_list2 = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
# Your code goes below here

p = the_list.pop(3)

s = the_list.insert(0, p)

the_list.remove("a")
the_list.remove(False)
the_list.remove([1, 2, 3])

the_list.extend(the_list2)
``` ```the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
index = the_list.pop(3)
the_list.insert(0, index)
the_list.remove("a")
del the_list
del the_list
print (the_list)
#checks and loops until the last number in the list reaches 20
while the_list[-1] != 20:
#add 1 to the last number in the list every time it loops and append it to the_list
the_list.append(the_list[-1] + 1)
print (the_list)
```

if anyone needs help this is the solution, but be sure to read through and understand

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("a") the_list.remove(False) the_list.remove([1,2,3])

the_list.extend(range(3, 21))