[Tutor] please help!
Gregor Lingl
glingl@aon.at
Fri Jan 10 05:51:25 2003
geraldine lynch schrieb:
> hello
>
> How do I sum all the elements of an array? I mean, is there a Capital
> sigma function? something like this:
>
> å y_i
>
Yes, you can use the builtin function reduce for this ...
> I'm quite new to python and have to write a program before my uni term
> restarts so i dont have very long!
>
... immediately:
>>> from operator import add
>>> reduce(add,[1,2,3,4,5,6])
21
reduce is even more versatile than this "Capital sigma" (- which,
incidentally,
on my email-client appears like the å in Lyckå), for instance:
>>> from operator import mul
>>> reduce(mul,[1,2,3,4,5,6])
720
Was this fast e3nough?
Regards, Gregor
> thanks, Geraldine
>
>
> ------------------------------------------------------------------------
> *With Yahoo! Mail you can get a bigger mailbox -- choose a size that
> fits your needs*
> <http://uk.yahoo.com/mail/tagline_xtra/?http://uk.docs.yahoo.com/mail_storage.html>