pitabread’s explanation is a good one and
print() statements are everyone’s friend (I use them all the time).
I think that maybe you’re confused about the parameters of the function(?). You are providing a list and the starting index and ending index, right?
So, with this:
print(middle_numbers_removed([4, 56, 48, 64, 16, 23], 1, 3))
You’re starting at index 1, which is…56 and the ending point index is 3, which is 64.
Your function logic,
return lst[:start] will give you the item at the beginning of the list to the stop point, the stop point in the function call is index 1, so that’s the number 56 and it is excluded. What is returned is the number 4 which is at index 0.
This part of the function:
+ lst[end+1:] will give you the end of the list (whatever the number is) plus 1 (ie: moving to the right). The end here is index 3, which is the number 64 in the list, +1 to that is 16 and 23.
So, what’s returned is
[4, 16, 23]
This can be a tricky one and in order to understand what the logic is doing it might be a good idea to provide different lists and starting & ending indicies so you can understand what the function logic is doing here. For example, what is the output with this, etc?
print(remove_middle([4, 56, 48, 64, 16, 23], 2, 4))