0

Pardon my low-tech question, but either I'm going insane, or this simply doesn't exist.
I get that you can do 5 * 5 and that will work, basic Python.
You can even do operator.mul(5, 5). But why is there no helper function for multiplication over a iterable?

I'm surprised to find that mul() isn't a standard built-in, or at the very least being a reference to it in either of the two main docs you end up in searching for mathematical functions. But also that there's no helper function called times(iterable) (or similar) that takes a iterable as an argument, much like sum(). It would for instance be handy when calculating the area size of a image if the image size is given as a tuple/list.

Am I blind or is there a reason for this? Isn't multiplication used that much?

Jongware
  • 22,200
  • 8
  • 54
  • 100
Torxed
  • 22,866
  • 14
  • 82
  • 131
  • @roganjosh Seriously don't know why I didn't got that in any search result or in the SO "similar posts" when posting. I've gone through hundreds of pages. My bad obviously, but that's a bit strange. – Torxed Mar 22 '18 at 20:19
  • "python product function" first search, first result :) Guess it just depends how you see the question in your head when searching – roganjosh Mar 22 '18 at 20:20
  • What's your first result if you search that term btw? I'm curious about whether my previous searches might have had a big impact on what I see compared to another Python user – roganjosh Mar 22 '18 at 20:22
  • @roganjosh Probably. I also didn't think it was called product. Went for `multiplication`, `times`, `multiply` and `iterable`. Should probably have covered this in grade school language classes heh :) – Torxed Mar 22 '18 at 20:22
  • @roganjosh It points to: https://docs.python.org/2/library/itertools.html followed by https://lists.gt.net/python/dev/704781 (using your search term, mine got me no where near) – Torxed Mar 22 '18 at 20:23
  • 1
    Perhaps you use `itertools` more than me :) I rarely search for the documentation because I don't use it often. – roganjosh Mar 22 '18 at 20:28

0 Answers0