[Python-il] Silly Python riddle

Ram Rachum ram at rachum.com
Sat Dec 17 17:03:55 IST 2011


On Sat, Dec 17, 2011 at 5:01 PM, Shai Berger <shai at platonix.com> wrote:

> On Saturday 17 December 2011, Ram Rachum wrote:
> > Here's a silly Python riddle for you.
> >
> > Today I opened up a Python 2.7 shell, and ran two commands in it.
> >
> > >>> f = lambda: g(???)
> > >>> f()
> >
> > (Note that these are the only commands that I ran. You're not allowed to
> > run any other commands before them.)
> >
> > The riddle: What's the shortest thing you can put instead of *???* so my
> > second command would not raise an exception?
> >
> I have a cheating solution that goes down to 3: """
>
> It's cheating because your second line is not a command (and in fact, it
> makes
> the whole thing not yet a commnd):
>
> >>> f = lambda: g(""")
> ... f()
> ...
>
> But still, at this point, no exception has been raised.
>
>
Yeah, that's a good cheat :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://hamakor.org.il/pipermail/python-il/attachments/20111217/3d984b5a/attachment.htm>


More information about the Python-il mailing list