Python: Mapping with Index of Previous Occurrence
<p>I'm often met with an analog of the following problem, and have had trouble writing clean code to solve it. Usually, I have something involving a temporary variable and a for loop, but is there a more elegant way?</p>

<p>Suppose I have a list of booleans or values which evaluate to booleans:</p>

<pre><code>[True, False, True, False, False, True]
</code></pre>

<p>How would I map this to a list of values, with the index of the previous True, inclusive?</p>

<pre><code>[0, 0, 2, 2, 2, 5]
</code></pre>

<p>[EDIT] Have tried something along the lines of:</p>

<pre><code>def example(lst):
    rst, tmp = [], None
    for i in range(len(lst)):
        if lst[i]:
            tmp = i
        rst.append(tmp)   
    return rst
</code></pre>

<p>Assuming the first element of the list is always True.</p>
