[Solved] running through a loop and find a condition that match


Print '#' if red else print '.'. If encounted sequence red, not red then print '.' for the rest of the array:

prev = None
it = iter(data)
for point in it:
    if point == 'red':
       print '#',
    else:
       print '.',
       if prev == 'red': # encounted ['red', 'blank']
          break
    prev = point

for point in it:
    print '.',
print

Example

blank blank red red blank red blank red red
. . # # . . . . .

solved running through a loop and find a condition that match