conditions tree and backtrace
<p>I have some graphs and I generates code from them. One condition from one node. For example generated code can look like this one:</p>

<pre><code>def function():
    steps = []

    if True:
        steps.append(1)

        if True:
            steps.append(2)

            if False:
                steps.append(3)
                return 'a', steps

            if False:
                steps.append(4)
                return 'b', steps


        if True:
            steps.append(5)

            if True:
                steps.append(6)

                if False:
                    steps.append(7)
                    return 'a', steps
            if True:
                steps.append(8)
                return 'b', steps
</code></pre>

<p>I replaced real conditions with <code>True</code>/<code>False</code> to make example cleaner.</p>

<p>This function return tuple <code>('b', [1, 2, 5, 6, 8])</code>, so some value and steps which was taken. I want modify this code to remove steps which was not successful. So after modification function should return <code>('b', [1, 5, 8])</code>. </p>

<p>My question is, what is the best way to do this?</p>
