title: Why is my lambda expression for reduce not working as expected?
body: <pre><code>&gt;&gt;&gt; import functools
  &gt;&gt;&gt; functools.reduce(lambda acc, val: acc + 1 if val == ' ' else 0, list("test test test"), 0)
  0
  </code></pre>
  
  <p>I just want to count whitespaces in the text so I expected the function to return <code>2</code> (because there are two whitespaces) not <code>0</code>.</p>