I have two lists
l1 = [0,1,2,2,0,1,1,0]
l2 = [(0,2),(3,5),(6,8),(9,10),(11,15),(16,18),(19,20),(21,22)]
If there is a sequence of 1s and 2s in the first list, followed by 1 or 0, then I want it to return the first element of the tuple in the corresponding index in the second list and the second element of the tuple of the final 2. Same if it is just 1, followed by o or 1.
So the output here should be
out = [(3,10),(16,18),(19,20)]
This is what I have
for index, item in enumerate(true):
if item == 0:
continue
elif item == 1 or item == 2:
if true[index+1] == 0 or true[index+1] == 1:
out.append(offsets[index])
elif true[index+1] == 2:
out.append((offsets[index][0], offsets[index+1][1]))
which results in
[(3, 8), (6, 10), (9, 10), (16, 18), (19, 20)]
Is there a more pythonic (and correct) way of approaching this?