[Tutor] Are you allowed to shoot camels? [kinda OT]

Alan Gauld alan.gauld at freenet.co.uk
Mon Feb 7 20:28:34 CET 2005


> As an aside, I did try to create a lambda based solution but was
unable.
> Let me know what's wrong:
>
> ftable = { 'a' : lambda: print 'a',
> SyntaxError: invalid syntax

I did say "if Python had *proper* lambdas..."

Unfortunately Python insists on only having *expressions* as
lambdas and since print is a command not a function you can't
use it in Python lambdas! Dumb or what??!

So you are stuck with predefining a bunch of one liner
functions and then creating a dictionary or going back
to if/elif chains, which is where we came in... :-)

HTH,

Alan G.



More information about the Tutor mailing list