News for hackers. Stuff that matters.
Re:Silly Python riddle by ul5255 on Tuesday December 20, 2011 @12:10PM (#3374177)
Strange. With Python 2.6 I get [None, 7] while with Python 2.7 it is [None]. Looking at the OP codes the 2.7 one's look weird.

Python 2.6:

  >>> dis.dis(f)
    1           0 LOAD_GLOBAL              0 (g)
                3 LOAD_CONST               0 (None)
                6 YIELD_VALUE
                7 CALL_FUNCTION            1
               10 RETURN_VALUE
Python 2.7:

  >>> dis.dis(f)
    1           0 LOAD_GLOBAL              0 (g)
                3 LOAD_CONST               0 (None)
                6 YIELD_VALUE
                7 CALL_FUNCTION            1
               10 POP_TOP
               11 LOAD_CONST               0 (None)
               14 RETURN_VALUE
In essence the Python 2.7 compiler decides to throw away the result of the g() function call and replaces it with None. Does anyone understand why?
Re:Silly Python riddle by martin_k on Tuesday December 20, 2011 @12:26PM (#3374248)
Re:Silly Python riddle by ul5255 on Tuesday December 20, 2011 @02:38PM (#3374787)
Ahh, thanks!