I am trying to generate a new list which is a subset of a given list, between the specified start index and the end index - 1. I am confused on what I am doing wrong because I keep getting empty brackets.
For example, when I start a REPL in python. Given a list
>>> a_list = [10, 20, 30, 40]
>>> sub(a_list, 1, 3)
[20, 30]
I want the output to look like the above.
How do I accomplish this?
Here is my code right now.
def sub(new_list: list[int], start: int, end: int) -> list[int]:
"""Generate a list which is a subset of the given list."""
a_list: list[int] = list()
i: int = 0
while i < len(new_list):
if i <= start and end <= i:
a_list.append(i)
i += 1
return a_list
Thank you!