Supersedes: <
prod-20220707195304@ram.dialup.fu-berlin.de>
[added ", 1"]
"Michael F. Stemper" <
michael.stemper@gmail.com> writes:
sum() is wonderful.
nums = [1,2,3]
sum(nums)
6
product(nums)
This is a contrived example. As such, it does not represent
real-world statistics about the frequency of the need for
"product" versus "sum".
I understand that there is no product() or prod(). Does anybody
here know why that was not included in the language? It seems
as if it would be useful, so there must have been some rationale
for that decision.
Unlike "+", "sum" is not part of the languge proper,
but of the standard library. Everything comes at a cost,
so the frequency of its usage must outweigh the costs of
its inclusion.
product = lambda i: functools.reduce( operator.mul, i, 1 )
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)