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

what to do exactly?

is the output supposed to be empty, or a list with an empty list? Not sure about bracketing in your task: a) Use .remove() and/or del to remove [the string, boolean, and list] members of the_list or b) Use .remove() and/or del to remove the string, boolean, and [list members] of the_list ??? Thank you!

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,064 Points

In each task, the goal is to operate on the_list to modify it according to the instructions. There are many operations that operate on a list "in place" which means changing the_list without reassigning to another variable. Your code will be a series of statement affecting the_list. List methods to use are:

  • .pop() removes the last item from a list,
  • .pop(index) removes the item from a list at that index
  • `.insert(index, item) inserts an item into list at position index
  • `.remove(item) removes the first occurrence of that item from list
  • `.extend(list) extends a list with the members from another list

For example:

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

# Remove the '1' from the list
the_list.pop(3)
# Insert the '1' into the first position
the_list.insert(0, 1)
# or in one step
the_list.insert(0, the_list.pop(3))

You solution will be a series of these list altering statements. Post back if you need more hints.

So it's a)? I am not supposed to alter the embedded list except delete it? I am perhaps over-thinking it, but altering the embedded list is also a possible alteration of the_list, isn't it? I seem to be unable to solve either anyway, and that's why I decided to beg for full solution in another post. I have really tried hard, but now I have to move on. Thanks for your prompt reply!

Chris Freeman
Chris Freeman
Treehouse Moderator 68,064 Points

I've posted a solution to your other question. In short, the challenge is about manipulating the given list through a series of statements. Each statement making an individual change, but when run all together manipulate the list to the goal of the challenge.

Parvinder Grewal
Parvinder Grewal
3,678 Points

Thank you for those bullet points. That helped me solve a question.