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

lists.py
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)

the_list.remove("a")
del the_list[3]
del the_list[3]

x = 20

for i in x:
    if not i in my_list: 
        the_list.append(i)
        i = i + 1
    else:
        i = i + 1
        continue

1 Answer

Ryan S
Ryan S
27,276 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: 
        the_list.append(i)

Hope this helps.