Skip to content

Instantly share code, notes, and snippets.

@richardpascual
Last active June 17, 2021 18:45
Show Gist options
  • Save richardpascual/35a501c7e8c4e4fefacc0dc059d0ee3c to your computer and use it in GitHub Desktop.
Save richardpascual/35a501c7e8c4e4fefacc0dc059d0ee3c to your computer and use it in GitHub Desktop.
Remove middle of a list based on parameters identifying the index range
#Write your function here
def remove_middle(lst, start, end):
vals = lst
for num in range(start, end):
del vals[num]
return vals
#Uncomment the line below when your function is done
print(remove_middle([4, 8, 15, 16, 23, 42], 1, 3))
#Alternate solution
def remove_middle(lst, start, end):
return lst[:start] + lst[end+1:]
@richardpascual
Copy link
Author

I had some problems with removing the list item at the end, inclusive to the end index id.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment