I have a list of booleans like
l = [False, False, False, True, True, True, False, False, True, False, False]
and want to invert every edge value that is False
like
[True, True, True, True, True, True, False, False, True, True, True]
What is the most pythonic way to achieve that?
Possibly there's some clever one-line solution for this, but until someone comes up with it, here's a way to do it with old fashioned iteration:
seq = [False, False, False, True, True, True, False, False, True, False, False]for i in range(len(seq)):if seq[i]:breakseq[i] = Truefor i in range(len(seq)-1, -1, -1):if seq[i]:breakseq[i] = Trueprint(seq)
Result:
[True, True, True, True, True, True, False, False, True, True, True]