# From what i can tell, this code gives no indication that it should see the middle number of a list- how does it know to do so?

#Write your function here

def remove_middle(my_list, start, end):

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

#Uncomment the line below when your function is done

print(remove_middle([4, 8, 15, 16, 23, 42], 1, 3))

output was:
[4, 23, 42]

It knows this because you defined a function that takes in three arguments. In this case itâ€™s a list as my_list, an int as start, and an int as end. The function is returning the data by â€ślist slicingâ€ť to parse the data.

It looks correct to me. Perhaps reviewing the â€śWorking with Lists in Pythonâ€ť Lesson in the â€śLearn Python 3â€ť syllabus might help you.

Additional info: list[:n] will count to nâ€™s index and include everything before it. list[n:] will slice value nâ€™s index and include everything to the right of it inclusive.

I donâ€™t know if I explained it well, but I included it in case you didnâ€™t want to review â€śWorking with Lists in Pythonâ€ť.

1 Like

ah, so itâ€™s not so much targetting the middle as much as just targetting the index that its told to which happens to be the middle?

Close. When slicing a list with the â€ślist[n:], list[:n], list[n:n]â€ť (you can use a number after another ":"operator to denote syntax itâ€™s targeting a specified index and then depending on which side of the â€ś:â€ť operator the number is on determines which direction the list will be sliced.

For example because my_list[end+1:] would be starting at index 4 include everything to the right.
Also, my_list[:start] would be starting at index 1 and includes everything to the left of it. (Note that this will not include index one, but instead everything to the left of it.)

Additionally, you could grab the remaining numbers in the list by slicing it like this my_list[start:end+1]. The slice will start at index one and include everything to right right of it, but because there is an index (which is derived by end+1) on both sides of the â€ś:â€ť operator it stops at the second index. Not that the slice is exclusive with respects to the index on the right side of the â€ś:â€ť operator.

1 Like

I said â€śNot that the slice is exclusive with respects to the index on the right side of the â€ś:â€ť operator.â€ť, But I meant â€śNote that the sliceâ€¦â€ť