[BangPypers] diffrerence between lambda function and ordinary one
Shashwat Anand
anand.shashwat at gmail.com
Fri Aug 6 16:45:09 CEST 2010
>
>
>
> You can write code like this:
>
> from operator import add
> print reduce(add, filter(lambda x: x%2==0, xrange(10)))
>
> to print the sum of even numbers less than 10
> instead of:
> tot = 0
> for i in xrange(10):
> ....if i%2 == 0:
> ........tot += i
> print tot
>
> ...
>
I would prefer LC anyway:
>>> sum(i for i in range(0,10,2))
20
--
~l0nwlf
More information about the BangPypers
mailing list