I think f = lambda:g();g=( ... f()
On Sat, Dec 17, 2011 at 6:32 PM, <[email protected]> wrote: > Send Python-il mailing list submissions to > [email protected] > > To subscribe or unsubscribe via the World Wide Web, visit > http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il > or, via email, send a message with subject or body 'help' to > [email protected] > > You can reach the person managing the list at > [email protected] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-il digest..." > > > Today's Topics: > > 1. Re: Silly Python riddle (asaf greenberg) > 2. Re: Silly Python riddle (Omer Zak) > 3. Re: Silly Python riddle (Ram Rachum) > 4. Re: Silly Python riddle (Shai Berger) > 5. Re: Silly Python riddle (Ram Rachum) > 6. Re: Silly Python riddle (Ram Rachum) > 7. Re: Silly Python riddle (Alon Levy) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Sat, 17 Dec 2011 16:27:24 +0200 > From: asaf greenberg <[email protected]> > Subject: Re: [Python-il] Silly Python riddle > To: [email protected] > Message-ID: <[email protected]> > Content-Type: text/plain; charset="us-ascii" > > An HTML attachment was scrubbed... > URL: < > http://hamakor.org.il/pipermail/python-il/attachments/20111217/3fae3528/attachment-0001.htm > > > > ------------------------------ > > Message: 2 > Date: Sat, 17 Dec 2011 16:38:42 +0200 > From: Omer Zak <[email protected]> > Subject: Re: [Python-il] Silly Python riddle > To: Python User Group <[email protected]> > Message-ID: <1324132722.3846.18.camel@c4> > Content-Type: text/plain; charset="UTF-8" > > Another attempt at golfing down the solution: > >>> f=lambda:g(0);g=(id) > >>> f() > 10482512 > > The solution is '0);g=(id', 8 characters long. > If there is a built-in function whose name is 1-character long, then the > solution can be made to be 7 characters long. > > > On Sat, 2011-12-17 at 14:55 +0200, Omer Zak wrote: > > I do not have Python 2.7, so I did the following on Python 2.6.6. > > >>> f = lambda: g(); g = lambda:() > > >>> f() > > () > > >>> > > > > In other words, '???' is replaced by '); g = lambda:(' > > > > --- Omer > > > > > > On Sat, 2011-12-17 at 14:14 +0200, 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? > > > > > > -- > $ python > >>> type(type(type)) > <type 'type'> My own blog is at http://www.zak.co.il/tddpirate/ > My opinions, as expressed in this E-mail message, are mine alone. > They do not represent the official policy of any organization with which > I may be affiliated in any way. > WARNING TO SPAMMERS: at http://www.zak.co.il/spamwarning.html > > > > ------------------------------ > > Message: 3 > Date: Sat, 17 Dec 2011 16:41:14 +0200 > From: Ram Rachum <[email protected]> > Subject: Re: [Python-il] Silly Python riddle > To: Omer Zak <[email protected]> > Cc: Python User Group <[email protected]> > Message-ID: > <CANXboVYLqt8UVrhYGP=C-18P=xTTnWjrbu6JJFfKO4C2=5r...@mail.gmail.com > > > Content-Type: text/plain; charset="iso-8859-1" > > Haha, I didn't think of all those creative answers when I asked this > riddle! I'm sure happy that none of them (so far!) have reached 7 > characters, which is the length of my solution. > > On Sat, Dec 17, 2011 at 4:38 PM, Omer Zak <[email protected]> wrote: > > > Another attempt at golfing down the solution: > > >>> f=lambda:g(0);g=(id) > > >>> f() > > 10482512 > > > > The solution is '0);g=(id', 8 characters long. > > If there is a built-in function whose name is 1-character long, then the > > solution can be made to be 7 characters long. > > > > > > On Sat, 2011-12-17 at 14:55 +0200, Omer Zak wrote: > > > I do not have Python 2.7, so I did the following on Python 2.6.6. > > > >>> f = lambda: g(); g = lambda:() > > > >>> f() > > > () > > > >>> > > > > > > In other words, '???' is replaced by '); g = lambda:(' > > > > > > --- Omer > > > > > > > > > On Sat, 2011-12-17 at 14:14 +0200, 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? > > > > > > > > > > -- > > $ python > > >>> type(type(type)) > > <type 'type'> My own blog is at http://www.zak.co.il/tddpirate/ > > My opinions, as expressed in this E-mail message, are mine alone. > > They do not represent the official policy of any organization with which > > I may be affiliated in any way. > > WARNING TO SPAMMERS: at http://www.zak.co.il/spamwarning.html > > > > _______________________________________________ > > Python-il mailing list > > [email protected] > > http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://hamakor.org.il/pipermail/python-il/attachments/20111217/920f617f/attachment-0001.htm > > > > ------------------------------ > > Message: 4 > Date: Sat, 17 Dec 2011 17:01:29 +0200 > From: Shai Berger <[email protected]> > Subject: Re: [Python-il] Silly Python riddle > To: [email protected] > Message-ID: <[email protected]> > Content-Type: Text/Plain; CHARSET=US-ASCII > > 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. > > > ------------------------------ > > Message: 5 > Date: Sat, 17 Dec 2011 17:03:55 +0200 > From: Ram Rachum <[email protected]> > Subject: Re: [Python-il] Silly Python riddle > To: Shai Berger <[email protected]> > Cc: [email protected] > Message-ID: > <canxbovaaguyrhohtvdvxckbm25qnyqhjrqzkrcrvpfvbveh...@mail.gmail.com > > > Content-Type: text/plain; charset="iso-8859-1" > > On Sat, Dec 17, 2011 at 5:01 PM, Shai Berger <[email protected]> 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-0001.htm > > > > ------------------------------ > > Message: 6 > Date: Sat, 17 Dec 2011 18:27:38 +0200 > From: Ram Rachum <[email protected]> > Subject: Re: [Python-il] Silly Python riddle > To: Shai Berger <[email protected]>, python-il > <[email protected]> > Message-ID: > <CANXboVbypSFHwp=xygsbs1r9arzcp+euctp945bffem6lfc...@mail.gmail.com > > > Content-Type: text/plain; charset="iso-8859-1" > > On Sat, Dec 17, 2011 at 6:14 PM, Shai Berger <[email protected]> wrote: > > > > > > > > (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? > > > > > > > > ???= (yield) > > > > right? > > > > (mailed privately, to avoid ruining the fun...) > > > > Yep!!! I just almost finished writing the email to tell everyone that when > I got your answer. > > Congrats for solving the riddle Shai. > > So as Shai said, the solution is: > > > > **>>> f = lambda: g(*(yield)*) > > >>> f() > > > Funny, isn't it? I was surprised to see that the `yield` keyword can be > used in a lambda function. > > So when you type `f()`, it just returns a generator. If you'll try to > exhaust it, an exception will be raised because `g` doesn't exist, but > that's a new line :) > > It's funny that in this case, Python seems to throw away the value of the > lambda function! As we know, the `yield` keyword actually forms a statement > whose value is `None`, unless you used the generator's `.send` instead of > `.next`. So you could also use `.send` to send in whatever value you want > into the lambda function, and Python will just throw it away. Unless I'm > missing something. > > So that's the only case I can think of where Python completely throws away > the value of a lambda function. > > > Another funny thing that I learned from this riddle is that when you do a > function invocation in Python, Python accesses the function *before* it > looks at the arguments. > > So if were to do: > > adfgadgof(1 / 0) > > > Python will complain about the non-existent function before it even sees > the division-by-zero. > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > http://hamakor.org.il/pipermail/python-il/attachments/20111217/a26b4ec7/attachment-0001.htm > > > > ------------------------------ > > Message: 7 > Date: Sat, 17 Dec 2011 18:34:11 +0200 > From: Alon Levy <[email protected]> > Subject: Re: [Python-il] Silly Python riddle > To: Ram Rachum <[email protected]> > Cc: python-il <[email protected]>, Shai Berger > <[email protected]> > Message-ID: > <calijepyizu7z2djctvteexi1ojgolzkhtf7tzwos_pz12mj...@mail.gmail.com > > > Content-Type: text/plain; charset=UTF-8 > > cute and interesting. > > On Sat, Dec 17, 2011 at 6:27 PM, Ram Rachum <[email protected]> wrote: > > On Sat, Dec 17, 2011 at 6:14 PM, Shai Berger <[email protected]> wrote: > >> > >> > > >> > (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? > >> > > >> > > >> ???= (yield) > >> > >> right? > >> > >> (mailed privately, to avoid ruining the fun...) > > > > > > Yep!!! I just almost finished writing the email to tell everyone that > when I > > got your answer. > > > > Congrats for solving the riddle Shai. > > > > So as Shai said, the solution is: > > > >> > >> >>> f = lambda: g((yield)) > >> >>> f() > > > > > > Funny, isn't it? I was surprised to see that the `yield` keyword can be > used > > in a lambda function. > > > > So when you type `f()`, it just returns a generator. If you'll try to > > exhaust it, an exception will be raised because `g` doesn't exist, but > > that's a new line :) > > > > It's funny that in this case, Python seems to throw away the value of the > > lambda function! As we know, the `yield` keyword actually forms a > statement > > whose value is `None`, unless you used the generator's `.send` instead of > > `.next`. So you could also use `.send` to send in whatever value you want > > into the lambda function, and Python will just throw it away. Unless I'm > > missing something. > > > > So that's the only case I can think of where Python completely throws > away > > the value of a lambda function. > > > > > > Another funny thing that I learned from this riddle is that when you do a > > function invocation in Python, Python accesses the function before?it > looks > > at the arguments. > > > > So if were to do: > > > >> adfgadgof(1 / 0) > > > > > > Python will complain about the non-existent function before it even sees > the > > division-by-zero. > > > > _______________________________________________ > > Python-il mailing list > > [email protected] > > http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il > > > > > > -- > Alon Levy > > > ------------------------------ > > _______________________________________________ > Python-il mailing list > [email protected] > http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il > > > End of Python-il Digest, Vol 48, Issue 5 > **************************************** >
_______________________________________________ Python-il mailing list [email protected] http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
