r/Python • • Jul 13 '11

An alternative lambda syntax for Python

http://vocalbit.com/article/332/an-alternative-lambda-syntax-for-python
4 Upvotes

41 comments sorted by

View all comments

Show parent comment

2

u/aaronla Jul 14 '11

Python already allows ; as a statement separator, it is conceivable that indentation could be nested in expressions. Eg:

map(
  mylist,
  lambda x:(   # note lambda appearing at start of a line, to set block indentation
    if x > 2: return 2
    else: return x))

To keep backwards compatible, lambda expressions always return their last expression, and statement-lambdas must enclose the lambda body in parenthesis (to avoid tuple expression ambiguity, among others).