Last active
June 17, 2021 18:45
-
-
Save richardpascual/35a501c7e8c4e4fefacc0dc059d0ee3c to your computer and use it in GitHub Desktop.
Remove middle of a list based on parameters identifying the index range
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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:] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had some problems with removing the list item at the end, inclusive to the end index id.