I'm wondering whether there's a more pythonic way to get an interval from a list knowing the beginning and ending values while only traversing the list once.
Example of what I want in a not very pythonic manner (stores all names between 'Ann' and 'John' inclusive):
all_names = []
start_adding = False
for name in names:
if name == 'Ann':
start_adding = True
if start_adding:
all_names.append(name)
if name == 'John':
break