feature request: mul

Gerrit Holl gerrit at nl.linux.org
Wed Jun 18 18:04:39 EDT 2003


Jacek Generowicz wrote:
> mis6 at pitt.edu (Michele Simionato) writes:
> > import operator
> > multi_and=lambda it: reduce(operator.mul,it)
> > if multi_and(condition):
> >    dosomething()
> > 
> > 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.
> You don't like abstraction ?

One could also use:
sum(map(bool, it)) or sum(map(abs, it)).

I have two use cases in my program. One is with a (200-elem) list of
booleans (pygame.keys.get_pressed()). One is with coordinates for a
direction, [-1 - 1, -1 - 1]. Because of this thread, I encountered
this bug and fixed it :)

yours,
Gerrit.

-- 
137. If a man wish to separate from a woman who has borne him children,
or from his wife who has borne him children: then he shall give that wife
her dowry, and a part of the usufruct of field, garden, and property, so
that she can rear her children. When she has brought up her children, a
portion of all that is given to the children, equal as that of one son,
shall be given to her. She may then marry the man of her heart.
        -- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/





More information about the Python-list mailing list