feature request: mul
mis6 at pitt.edu
Wed Jun 11 18:33:33 CEST 2003
I like the new builtin 'sum', actually I missed it from my very first
Python program (I was doing hystograms at that time). Here is the question:
is there any hope to have a corrisponding 'mul' in the near future?
Of course, you could use 'mul' to compute factorials, bu my motivation is
mainly for logical constructs.
At the present, instead of
if condition or condition or .... or condition:
I can use (using a comment to make crystal clear what the code is doing)
if sum(condition): # multi_or
In the same sense, I would like to abbreviate
if condition and condition and .... and condition:
if mul(condition): # multi_and
I know I could use
multi_and=lambda it: reduce(operator.mul,it)
but frankly it is too ugly for my taste. Having
'sum' and 'mul' the use cases for 'reduce' would
drop, which I think is a good thing.
Apart for boolean algebra, I think a 'mul' with
would naturally complement 'sum'. Moreover,
the implementation would be trivial and I don't
see why we should not have it.
P.S. BTW, I like the concept of reduce, but
not the syntax, and that is the reason why
I *never* use 'reduce' in my programs. A more
sensible syntax would have been something
but of course apply had another meaning.
More information about the Python-list