I want to iterate a given list based on a variable number of iterations stored in another list and a constant number of skips stored in as an integer.
Let's say I have 3 things -
l- a list that I need to iterate on (or filter)w- a list that tells me how many items to iterate before taking a breakk- an integer that tells me how many elements to skip between each set of iterations.
To rephrase, w tells how many iterations to take, and after each set of iterations, k tells how many elements to skip.
So, if w = [4,3,1] and k = 2. Then on a given list (of length 14), I want to iterate the first 4 elements, then skip 2, then next 3 elements, then skip 2, then next 1 element, then skip 2.
Another example,
#Lets say this is my original list
l = [6,2,2,5,2,5,1,7,9,4]
w = [2,2,1,1]
k = 1
Based on w and k, I want to iterate as -
6 -> Keep # w says keep 2 elements
2 -> Keep
2 -> Skip # k says skip 1
5 -> Keep # w says keep 2 elements
2 -> Keep
5 -> Skip # k says skip 1
1 -> Keep # w says keep 1 element
7 -> Skip # k says skip 1
9 -> Keep # w says keep 1 element
4 -> Skip # k says skip 1
I tried finding something from itertools, numpy, a combination of nested loops, but I just can't seem to wrap my head around how to even iterate over this. Apologies for not providing any attempt, but I don't know where to start.
I dont necessarily need a full solution, just a few hints/suggestions would do.