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

Gunhoo Yoon
Gunhoo Yoon
5,027 Points

Python code challenge problem.

I've done what the question asked for but it keeps saying task 1 is no longer correct during task 3 while I meet the requirement for task 1. Am I missing something here? Also, how do I make the task 2 simpler than what I wrote?

lists.py
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]

# Your code goes below here
# Move element 1 to index 0
target = the_list.pop(the_list.index(1))
the_list.insert(0, target)

# remove boolean, string, list in the_list
not_int = []
for item in the_list:
  if type(item) is not int:
    not_int.append(item)

for item in not_int:
  the_list.remove(item)

# let the_list have only numbers 1 ~ 20 by using extend()
the_list.extend(list(range(the_list[-1], 21)))
Gunhoo Yoon
Gunhoo Yoon
5,027 Points

I probably was overthinking it to make it somewhat useful and make use of what I learned from Python doc but yeah that works for sure. I was just curious how my answer altered the task 1.

I'm not sure why it makes task 1 fail. The output of both had the same result in the python shell. I did notice that both were adding an extra '3' into the list. I corrected it with the 3rd one by adding + 1

test = [1,2,3] test.extend(list(range(test[-1], 21))) print(test) [1, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] test = [1,2,3] test.extend(list(range(len(test), 21))) print(test) [1, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] test = [1,2,3] test.extend(range(len(test) + 1, 21)) print(test) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

Gunhoo Yoon
Gunhoo Yoon
5,027 Points

It's not a big deal I guess but thanks.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,064 Points

When an earlier task starts failing it is usually caused by a syntax error in the current task which makes all the tasks fail due to the syntax error.

1 Answer

task 3 for me turned out a tad different:

the_list.extend(list(range(len(the_list), 21)))

task 2: the_list.remove("a")

the_list.remove(False)

del the_list[3] # the index of the list [1,2,3] in the_list may be different depending on the order you remove "a" and False

Task 1 can be simplified also