HNHacker News
TopNewBestAskShowJobs

ul5255

67 karma · joined December 20, 2011

submissionscomments
ul5255··on Silly Python riddle
Whatever goes inside a lambda must be an expression. The parentheses around yield make it a yield expression. Otherwise yield would be a statement which is a different thing as far as Python is concerned.

You can also use it inside generators:

  >>> def f():
         while True:
             xyz = (yield)
             print xyz
  >>> g = f()
  >>> g.next()
  # nothing happens as xyz == None
  >>> g.send('huhu')
  huhu
ul5255··on Silly Python riddle
lurking around here for years ... this riddle finally made me register an account with HN ...
ul5255··on Silly Python riddle
>>> f = lambda: g((yield))

>>> f()

<generator object <lambda> at 0x00B50828>

← PreviousPage 2 of 2