This is 100% a dumb question but I couldn't find the answer. Would i be able to do a for loop between two different intervals?
Take for example:
array = [1,2,3,4,5,6,7,8,9,10]
for i in range(0,5) and range(7,9):
print(array[i])
and it would output: 1,2,3,4,5,8,9
Edit: As Adam.Er8 pointed out, itertools.chain, would be the cleaner solutions.
Another solution I found while experimenting was without the itertools would be:
array = [1,2,3,4,5,6,7,8,9,10]
needrange = [[1,3],[5,7],[8,9]]
for j in range(0,len(needrange)):
for i in range(needrange[j][0],needrange[j][1]):
print(array[i])
This solution isn't clean but it does do the job if you aren't looking to import.
Credit to cs95 from a similar question, who wrote:
ranges = [range(2, 5), range(3, 7), ...]
flat = list(chain.from_iterable(ranges))
Notes found while writing this response):
I'm pretty sure range(n,m) from cs95 answer just returns a list as well, whereas I just created a list initially. So very similar
The function from itertools,looks very similar logic wise, but I just found my solution easier to read.