title: Is there a javascript 'reduce()' like function in python?
body: <p>map() and filter() are good when it comes to applying a function individual elements, but there is no way to do any of the following with them on iterables :</p>
  <ol>
  <li>apply functions on a bunch of elements as a whole</li>
  <li>keep track of previously iterated elements / 'accumulate' items</li>
  <li>get the index of the current element under iteration</li>
  </ol>
  <p>All of these pose a challenge when you need to perform operations on the current element based on previous values or on a group of elements together like a sub-array.</p>
  <h3>example1 :  I want to iterate over and sum the elements one by one</h3>
  <pre><code>&gt;&gt;&gt; l = [4,7,2,8,10]
  &gt;&gt;&gt; map(sum,l)       # throws the following error
  Traceback (most recent call last):
    File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
    File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;lambda&gt;
  TypeError: 'int' object is not iterable
  </code></pre>
  <p>Not possible since sum cannot operate on single ints and there is no way to track the iterated values up till now!</p>
  <h3>example 2: I maintain a local variable to track the current sum</h3>
  <pre><code>&gt;&gt;&gt; curr = 0
  
  &gt;&gt;&gt; [* map(lambda x: curr+=x ,l)]
                           ^
      File &quot;&lt;stdin&gt;&quot;, line 1
      SyntaxError: invalid syntax
  </code></pre>
  <p>Again, not allowed since assignment or modification not allowed inside lambda!</p>
  <p>Both of these results are expected, but is there an easier functional alternative which is typically what the javascript reduce() function does?</p>