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

Randall Brewster
Randall Brewster
5,041 Points

Now, make the_list contain only the numbers 1 through 20 by using .extend().

please help im stuck

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

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

for item in list(the_list):
  if isinstance(item, (str, bool, list)):
    the_list.remove(item)

1 Answer

Joshua Ferdaszewski
Joshua Ferdaszewski
12,716 Points
  1. A note about your code: list(the_list) is redundant. the_list is already a python list so there is no need to call the list() function on it. You can simplify this line to be just for item in the_list:
  2. At the end of your script, the_list should be [1, 2, 3]. You need to add 4-20 to the list. I would recommend looking up the range() function and then think about how you can combine it with the_list using the .extend() method.

Good luck learning Python!