what's wrong with "lambda x : print x/60,x%60"

Dan Bishop danb_83 at yahoo.com
Tue Dec 6 01:30:36 EST 2005


bonono at gmail.com wrote:
> rurpy at yahoo.com wrote:
> > bonono at gmail.com wrote:
> > > rurpy at yahoo.com wrote:
> > > > >  and, as you just found out, a rather restrictive one
> > > > > at that.
> > > >
> > > > In part because Python's designers failed to make "print" a function
> > > > or provide an if-then-else expression.
> > > >
> > > Why would one need print in lambda ? I like ternary operator(and there
> > > is ugly work around though still 100% functional). But print ?
> >
> > I dashed that last part off quickly, so I don't have a good reason.
> > Maybe to insert a debugging print temporarily?
> If one needs it for debugging, it raise an alarm bell if lambda is the
> right thing to use. Though it is still doable, in a hackary way :
>
> def debug(x): print x
>
> reduce(lambda x,y: (x+y, debug(x))[0], range(10))

There's also

lambda x, y: sys.stdout.write('%s\n' % x) or x + y




More information about the Python-list mailing list