Hacker News new | ask | show | jobs
by kazinator 483 days ago
We can sort of make a shitty multi-line lambda in Python by making a dummy function called progn, and using it, like this:

  >>> def progn(*args):
  ...   if args:
  ...     return args[-1]
  ...   else:
  ...     return None
  ...
  >>> fun = lambda x : progn(print('abc'),
  ...                        print(x),
  ...                        print('def'))
  >>>
  >>> fun(42)
  abc
  42
  def

:)