On Thu, 7 Jul 2022 at 22:55, Michael F. Stemper
<michael.stem...@gmail.com> wrote:
>
> sum() is wonderful.
>
>   >>> nums = [1,2,3]
>   >>> sum(nums)
>   6
>   >>> product(nums)
>   Traceback (most recent call last):
>     File "<stdin>", line 1, in <module>
>   NameError: name 'product' is not defined
>   >>>
>
> 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.

There is math.prod:

  >>> from math import prod
  >>> prod([1, 2, 3, 4])
  24

https://docs.python.org/3/library/math.html#math.prod

--
Oscar
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to