This would serve a better example -
>>> sum( int(x) for x in raw_input().split() )
1 2 3 4
10
>>>
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listinfo/bangpypers
On Fri, Aug 6, 2010 at 8:37 PM, Pradeep Gowda wrote:
> On Fri, Aug 6, 2010 at 10:45 AM, Shashwat Anand
> wrote:
> > I would prefer LC anyway:
> >
> sum(i for i in range(0,10,2))
> > 20
>
> why use LC at all?
> >> sum(range(0,10,2))
>
>
^ I too have written such "i for i in ..." expressions
On Fri, Aug 6, 2010 at 8:37 PM, Pradeep Gowda wrote:
> On Fri, Aug 6, 2010 at 10:45 AM, Shashwat Anand
> wrote:
> > I would prefer LC anyway:
> >
> sum(i for i in range(0,10,2))
> > 20
>
> why use LC at all?
> >> sum(range(0,10,2))
>
Oops. Wrong choice of example.
--
~l0nwlf
On Fri, Aug 6, 2010 at 10:45 AM, Shashwat Anand
wrote:
> I would prefer LC anyway:
>
sum(i for i in range(0,10,2))
> 20
why use LC at all?
>> sum(range(0,10,2))
___
BangPypers mailing list
BangPypers@python.org
http://mail.python.org/mailman/listin
>
>
>
> 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
On Fri, Aug 6, 2010 at 10:20 AM, Rahul R wrote:
> i was writing some basic code . for understanding lambda functions , but
> couldnt understand the difference between a lambda function and an ordinary
> function.
>
> for example
>
def f (x): return x**2
> ...
print f(8)
64
g = l
2010/8/6 Rahul R :
> i was writing some basic code . for understanding lambda functions , but
> couldnt understand the difference between a lambda function and an ordinary
> function.
>
> for example
>
def f (x): return x**2
> ...
print f(8)
64
g = lambda x: x**2
print
>
>
> i was writing some basic code . for understanding lambda functions , but
> couldnt understand the difference between a lambda function and an ordinary
> function.
>
> for example
>
> >>>def f (x): return x**2
> ...
> >>> print f(8)
> >>> 64
> >>> g = lambda x: x**2
> >>>
> >>> print g(8)
> >>
i was writing some basic code . for understanding lambda functions , but
couldnt understand the difference between a lambda function and an ordinary
function.
for example
>>>def f (x): return x**2
...
>>> print f(8)
>>> 64
>>> g = lambda x: x**2
>>>
>>> print g(8)
>>> 64
wats a need for using la