0

I have several arrays of lines of output in a program that use '#' and ' '. The arrays could be any combination of these two elements, i.e.

[..., #, #, #, #, ' ', ' ', ...]
[..., #, #, ' ', ' ', #, #, ...]
[..., ' ', ' ', #, #, ' ', ' ', ...] etc.

Is there a way of trimming the start and end of the array to remove all ' ' until a # is found and leave all ' ' between the # alone?

1 Answers1

0

use join and rindex / index to find the last / first occurrence of #

res = ''.join(array).rindex('#')

then use del to delete everything before and after

del array[res:]