prod() does just what you want.

On Tue, Dec 4, 2012 at 5:53 PM, Michael Orlitzky <mich...@orlitzky.com> wrote:
> I've been carrying this around in my init.sage. Is there really nothing
> like it in the library? If not, any reason not to add it?
>
> ##
>
> from functools import reduce
>
> def product(factors):
>     """
>     Returns the product of the elements in the list ``factors``. If
>     the list is empty, we return 1.
>
>     EXAMPLES:
>
>     Normal integer multiplication::
>
>         sage: product([1,2,3])
>         6
>
>     And with symbolic variables::
>
>         sage: x,y,z = SR.var('x,y,z')
>         sage: product([x,y,z])
>         x*y*z
>
>     TESTS:
>
>     The empty product is the multiplicative identity (one)::
>
>         sage: product([])
>         1
>
>     """
>     return reduce(operator.mul, factors, 1)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sage-devel" group.
> To post to this group, send email to sage-devel@googlegroups.com.
> To unsubscribe from this group, send email to 
> sage-devel+unsubscr...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-devel?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To post to this group, send email to sage-devel@googlegroups.com.
To unsubscribe from this group, send email to 
sage-devel+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel?hl=en.


Reply via email to