Learning Python: Chapter 17

  • Anonymous functions are declared with lambda instead of def.
  • Lambda definitions are expressions and may therefore not contain if-statements and the like.
  • map(foo, list1, list2, list3) is like [foo(*tuple) for tuple in zip(list1, list2, list3)].
  • By using yield instead of return to provide a return value, you create a function that returns a generator object that returns one result at a time, somewhat like xrange.
    (expression for item in iterable) is like
    def foo():
      for item in iterable:
        yield expression
    foo()
  • Functions that don’t return anything explicitly return None.

Leave a Reply