Replace all negative values in a list
<p>I'm trying to solve this problem on codewars and I'm completely stumped:</p>

<pre><code>y = [-1, -1, 2, 8, -1, 4]
z = [1,3,5]
#to create [1,3,2,8,5,4]
</code></pre>

<p>How would I do this?</p>

<p>I tried to do:</p>

<pre><code>for e in range(len(y)):
    try:
        if y[e] &lt; 0:
            y[e] = z[e]
    except:
        pass
</code></pre>

<p>But this would only work if the negatives correspond to what is in z.</p>

<p>You're trying to use the same index for both lists, which doesn't appear to be the correct behaviour from your example. For example, the -1 in <code>y</code> is at index 4, but is replaced by the 5 in <code>z</code> at index 2.</p>

<pre><code>zindex = 0
for yindex in range(len(y)):
    if y[yindex] &lt; 0:
        y[yindex] = z[zindex]
        zindex += 1
</code></pre>

python python-3.x