Re: [BangPypers] diffrerence between lambda function and ordinary one

2010-08-06 Thread Abhishek Mishra
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

Re: [BangPypers] diffrerence between lambda function and ordinary one

2010-08-06 Thread Abhishek Mishra
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

Re: [BangPypers] diffrerence between lambda function and ordinary one

2010-08-06 Thread Shashwat Anand
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

Re: [BangPypers] diffrerence between lambda function and ordinary one

2010-08-06 Thread Pradeep Gowda
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

Re: [BangPypers] diffrerence between lambda function and ordinary one

2010-08-06 Thread Shashwat Anand
> > > > 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

Re: [BangPypers] diffrerence between lambda function and ordinary one

2010-08-06 Thread Pradeep Gowda
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

Re: [BangPypers] diffrerence between lambda function and ordinary one

2010-08-06 Thread Anand Chitipothu
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

Re: [BangPypers] diffrerence between lambda function and ordinary one

2010-08-06 Thread Zubin Mithra
> > > 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) > >>

[BangPypers] diffrerence between lambda function and ordinary one

2010-08-06 Thread 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 g(8) >>> 64 wats a need for using la