I have a list of values that are the result of merging many files. I need to pad some of the values. I know that each sub-section begins with the value -1. I am trying to basically extract a sub-array between -1's in the main array via iteration.
For example supposed this is the main list:
-1 1 2 3 4 5 7 -1 4 4 4 5 6 7 7 8 -1 0 2 3 5 -1
I would like to extract the values between the -1s:
list_a = 1 2 3 4 5 7
list_b = 4 4 4 5 6 7 7 8
list_c = 0 2 3 5 ...
list_n = a1 a2 a3 ... aM
I have extracted the indices for each -1 by searching through the main list:
minus_ones = [i for i, j in izip(count(), q) if j == -1]
I also assembled them as pairs using a common recipe:
def pairwise(iterable):
a, b = tee(iterable)
next(b, None)
return izip(a,b)
for index in pairwise(minus_ones):
print index
The next step I am trying to do is grab the values between the index pairs, for example:
list_b: (7 , 16) -> 4 4 4 5 6 7 7 8
so I can then do some work to those values (I will add a fixed int. to each value in each sub-array).