Issue 18646: Improve tutorial entry on 'Lambda Forms'. (original) (raw)

[0. On mailing lists, 'lambda expression' is used rather than 'lambda form'. Docs use both. Consistency across docs is a broader issue than this one. So leave title alone for this one.]

  1. (first sentence) "By popular demand, a few features commonly found in functional programming languages like Lisp have been added to Python." (in early Python 1!) I think this should just be deleted. See 4. below as a replacement.

  2. " With the lambda keyword, small anonymous functions can be created." Change to "Small anonymous functions can be created with the lambda keyword."

  3. change "Here’s a function that returns" to "This function returns"

3.5 add a sentence about the different between def and lambda (the name attribute.

  1. Add sentences about the purposes of lambda. Add an example that illustrates passing functions.

pairs = [(1, 'one'), (2, 'two'), (3, 'three'), (4, 'four')] pairs.sort(key=lambda pair: pair[1]) pairs [(4, 'four'), (1, 'one'), (3, 'three'), (2, 'two')]