FAQ: Code Challenge: Lists - Remove Middle


This community-built FAQ covers the “Remove Middle” exercise from the lesson “Code Challenge: Lists”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science
Data Science

FAQs on the exercise Remove Middle

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


This section of challenges has been incredibly frustrating to me. I went through the making and modifying lists instructions twice because I felt like I missed an entire segment of this lesson.
The language used to guide me through the code is very confusingly put. Maybe my brain is having trouble translating these problems into something that makes sense.
But for the life of me, I do not understand why the solution uses:
I don’t understand why we are adding 1 to the end slice of lst. This function is made to output a lst with a specific set of indices and doesn’t seem to really work if using a different set of numbers.
Some clarity would be greatly appreciated.

def remove_middle (lst, start, end):

The name suggests that all elements, including the one at index position, end will be removed. Recall that list slices do not include the index at end, but stop just before that position. If we do not add 1 then the element at position end will not be in the list slice.


Man, that +1 made me feel really dumb, because it looks simple now. I search for a .remove function on Google and used it do solution:

def remove_middle (lst, start, end):
new_lst = lst[:start] + lst[end:]
return new_lst


I knew about the .remove, however I don’t recall codecademy teaching us .remove


I found that to happen during the lessons, where the solution contains a way you haven’t learned yet. In a future lesson they will tell you to do an input and you haven’t learned it yet, so you just look at the answer and learn it that way.

I normally do it myself and then reset and take a look at the solutions every time. I try to see if they did it differently and if there something I could learn or how I could have done it better.


If the method hasn’t been taught yet, then don’t use it. Learn to work with what you have been taught up to the point and stop complaining about the course. The .remove method is not the solution for this problem so don’t even bother with it.

def remove_middle(lst,start,end):
  del lst[start: (end+1)]
  return lst

This may not be the solution they used but it works.
Pretty sure del was talked about earlier. Either way its self explanatory.
Google is your friend, this is a class not a instant pass to learn Python in 24 hours.
You will need to ask questions.


I think people have every right to complain about the course if we are having issues with it.

Since your a mod, maybe stop telling people to stop complaining and actually take in peoples criticism and issuses, afterall its only gonna help make the course better for everyone in the long run.

some of these coding challenges have been worded horrendously which makes things 10x harder to understand


One might if it were not completely out of our hands. The complaints need to be directed to Codecademy, not the forums. This is not a wailing wall.


Then maybe try pointing them in that direction instead of telling them just to stop doing it


#Write your function here
def remove_middle(lst, start, end):
if start < len(lst):
one_step = lst[:start]
if end <= len(lst):
two_step = lst[end+1:]
return one_step + two_step
#Uncomment the line below when your function is done
print(remove_middle([4, 8, 15, 16, 23, 42], 1, 3))


#Write your function here
def remove_middle(lst, start, end):
new_lst = lst[start:end+1]
for i in new_lst:
return lst
#Uncomment the line below when your function is done
print(remove_middle([4, 8, 15, 16, 23, 42], 1, 3))


Combining techniques is kind of redundant, but it is nice to see the .remove method used correctly, for a change. Combining two slices is a more direct approach…

    return lst[:start] + lst[end + 1:]


“Does your reply improve the conversation in some way?” “Be kind to your fellow community members”


I felt kind of the same way. But in the end I came up with this:

def remove_middle(lst, start, end):
    area_1 = 0 + start
    area_2 = ((len(lst)) - end - 1) * (-1)
    new_lst = lst[:area_1]
    new_lst2 = lst[area_2:]
    return new_lst + new_lst2

Seems a bit complicated but it work. Any suggestion how to simplify it?


Best suggestion is to think it through, piece by piece and determine what, if anything could be done differently. Us telling you how to simplify won’t help you. That’s where the work begins in learning to program.

Start with something that works, then tear it down and build it back up again, only different, each time. Eventually you will have a storehouse of alternate approaches, some simpler than others. Weigh out the pro’s and con’s for each, and you will be officially learning.


thanks for the quick reply;) I’ll try my best.


Why so complicated??

def remove_middle(lst, start, end):
return lst[:start] + lst[end+1:]


Wow i just spent so long trying to figure this one out. It’s the first time i have been completely stumped during this course and came to check the answer.

Cant believe you solved it with just a 1-liner - great :slight_smile: