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 trialShahar Polak
5,756 PointsThis code works but I can't submit the answer...
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
# Your code goes below here
first = the_list.pop(3)
the_list.insert(0,first)
temp_list = []
for item in the_list:
if type(item) == int:
if item > 0 and item <20:
temp_list.append(item)
the_list.extend(temp_list)
1 Answer
Iain Simmons
Treehouse Moderator 32,305 PointsFirst up, you don't have the code used for the second task to remove the string ("a"
), boolean (False
) or the nested list ([1, 2, 3]
). Add that first, and then the_list
would contain [1, 2, 3]
.
Second, you're only looping through the existing list and adding to the temp_list
. You need another list containing the numbers up until 20 that don't already exist in the_list
(i.e. 4 through 20).
Since you're 'extending' the list, you don't need to loop through what is already in there, you just need to somehow add what is missing.
Have a look at using range().
Shahar Polak
5,756 PointsShahar Polak
5,756 PointsGreat thanks, I've done it a bit differently using a helper variable list .