title: Returning the product of a list
body: <p>Is there a more concise, efficient or simply pythonic way to do the following?</p>
  <pre><code>def product(lst):
      p = 1
      for i in lst:
          p *= i
      return p
  </code></pre>
  <p>EDIT:</p>
  <p>I actually find that this is marginally faster than using operator.mul:</p>
  <pre><code>from operator import mul
  # from functools import reduce # python3 compatibility
  
  def with_lambda(lst):
      reduce(lambda x, y: x * y, lst)
  
  def without_lambda(lst):
      reduce(mul, lst)
  
  def forloop(lst):
      r = 1
      for x in lst:
          r *= x
      return r
  
  import timeit
  
  a = range(50)
  b = range(1,50)#no zero
  t = timeit.Timer(&quot;with_lambda(a)&quot;, &quot;from __main__ import with_lambda,a&quot;)
  print(&quot;with lambda:&quot;, t.timeit())
  t = timeit.Timer(&quot;without_lambda(a)&quot;, &quot;from __main__ import without_lambda,a&quot;)
  print(&quot;without lambda:&quot;, t.timeit())
  t = timeit.Timer(&quot;forloop(a)&quot;, &quot;from __main__ import forloop,a&quot;)
  print(&quot;for loop:&quot;, t.timeit())
  
  t = timeit.Timer(&quot;with_lambda(b)&quot;, &quot;from __main__ import with_lambda,b&quot;)
  print(&quot;with lambda (no 0):&quot;, t.timeit())
  t = timeit.Timer(&quot;without_lambda(b)&quot;, &quot;from __main__ import without_lambda,b&quot;)
  print(&quot;without lambda (no 0):&quot;, t.timeit())
  t = timeit.Timer(&quot;forloop(b)&quot;, &quot;from __main__ import forloop,b&quot;)
  print(&quot;for loop (no 0):&quot;, t.timeit())
  </code></pre>
  <p>gives me</p>
  <pre><code>('with lambda:', 17.755449056625366)
  ('without lambda:', 8.2084708213806152)
  ('for loop:', 7.4836349487304688)
  ('with lambda (no 0):', 22.570688009262085)
  ('without lambda (no 0):', 12.472226858139038)
  ('for loop (no 0):', 11.04065990447998)
  </code></pre>