+ and * operators

Stefan Franke spamfranke at bigfoot.de
Sun May 7 20:55:46 CEST 2000


That's what the operator module is good for:

>>> import operator
>>> operator.add(1, 2)
3
>>> operator.mul(4, 5)
20

Stefan


On Sun, 07 May 2000 20:43:21 +0200, Peter Schneider-Kamp
<petersc at stud.ntnu.no> wrote:

>Is there some way to refer to the + and *
>operators as functions?
>
>If e.g. I want to have the length of a
>vector v writing
>
>reduce(lambda x,y:x+y,map(lambda x:x*x,v))
>
>is not really nice. I'd like to write
>something like:
>
>reduce(+,map(*,v))
>
>thnx for advice
>Peter




More information about the Python-list mailing list