Why is Python popular, while Lisp and Scheme aren't?
Christian Tanzer
tanzer at swing.co.at
Mon Nov 11 02:51:29 EST 2002
Pascal Costanza <costanza at web.de> wrote:
> ...or some nice examples. ;)
>
> > (+ 1 1)
> 2
>
> > (+ 1 1 1)
> 3
>
> > (+ 1 1 1 2)
> 5
>
> > (+ 2)
> 2
>
> > (+)
> 0
>
> > (*)
> 1
Bah.
>>> import operator
>>> def plus(* args):
... return reduce(operator.add, args, 0)
...
>>> plus()
0
>>> plus(1)
1
>>> plus(1, 1)
2
>>> plus(1, 1, 1)
3
>>> plus(1, 1, 1, 2)
5
Implementing mul is left as an exercise <wink>.
--
Christian Tanzer tanzer at swing.co.at
Glasauergasse 32 Tel: +43 1 876 62 36
A-1130 Vienna, Austria Fax: +43 1 877 66 92
More information about the Python-list
mailing list