[Tutor] initialising all elements of a matrix

Peter Otten __peter__ at web.de
Tue Feb 28 19:03:32 CET 2012


bob gailer wrote:

> On 2/28/2012 11:40 AM, Peter Otten wrote:
> 
> def product(factors, product=1):
>      for factor in factors:
>          product *= factor
>      return product
> 
> can be "simplified"
> 
> def product(factors):
>    import operator
>    return reduce(operator.mul, factors)

If I had used the variant with reduce() would you have posted

> def product(factors):
>    return reduce(operator.mul, factors)
>
> can be "complexified"
> 
> def product(factors, product=1):
>      for factor in factors:
>          product *= factor
>      return product
 
(Just a pointless thought experiment)



More information about the Tutor mailing list