[Tutor] lambda

Alan Gauld alan.gauld at btinternet.com
Sat Jan 26 08:37:04 CET 2013


On 26/01/13 01:22, eryksun wrote:

> With a function call you no longer need the default parameter hack
> (i.e. x=i, y=j). You can make a closure over the local i and j in
> buttonFunMaker:
>
>      def buttonFunMaker(i, j):
>          def func():
>              return ttt(i, j)
>          return func

Good catch!

>      def buttonFunMaker(i, j):
>          return lambda: ttt(i, j)

Since the point was to get away from lambda I discounted this option, 
but it was my first instinct! :-)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list