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

Tobias Erhart
Tobias Erhart
2,481 Points

Why is this message coming?

I really don`t know why this message always pops up i cant find an error please help me

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

# Your code goes below here
num1 = the_list.pop(3)
the_list.insert(0, num1)

del the_list[3]
del the_list[3]

x = 20

for i in x:
    if not i in my_list: 
        i = i + 1
        i = i + 1

1 Answer

Ryan S
Ryan S
27,275 Points

Hi Tobias,

I think you are overcomplicating Task 3. The challenge specifically asks you to use .extend() so it's possible to pass this using one line of code.

But there are obviously many different ways to solve a problem and using a for loop like you are attempting is perfectly reasonable. You are on the right track, so I will comment on it anyways just to clear a few things up.

First, you have your "x" variable defined as a single integer. If you want to cycle through the numbers 1 to 20 using a for loop, you need to create a list of that range of numbers.

Second, your if statement has a typo. You are checking "my_list" when it should be "the_list"

And third, it is not necessary to increment your "i" variable as you are doing. The for loop will cycle through each item in "x" on its own. If you were using a while loop to solve this challenge then a counter variable like "i" would be useful.

So your code for task 3 could be reduced to the following:

x = list(range(1, 21))

for i in x:
    if not i in the_list: 

Hope this helps.