Python if else statement not working in reduce lambda function
<p>I'm new to <code>lambda</code> and <code>reduce</code> in Python and I don't understand why this function doesn't work:</p>

<pre><code>def my_func(str):
    symbols = ['_', '-']
    return reduce(lambda x, y: ' ' + y if x in symbols else x + y, str)

my_func('foo_bar-baz')  # 'foo_bar-baz'
</code></pre>

<p>I expected the output to be <code>'foo bar baz'</code>.</p>

<p>Does anyone understand what's wrong here?</p>