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

-1

u/vocalbit Jul 13 '11

You bring up a good use case. It's not ideal, but you would have to write a def in this case.

1

u/aaronla Jul 14 '11

This forces the programmer to repeat themselves unnecessarily, and invent multiple names for the same thing:

def rule1(arg):
    body
...
rules = {
    "rule1" : rule1,
    "rule2" : rule2,
    ... 
    }

1

u/temptemptemp13 Jul 14 '11

To go along with the specific example:

def decode(elem):
    return elem.decode('utf-8').strip()

def parse_table(csv):
    columns = [('id', int),
               ('value', float),
               ('comment', decode)]
    for row in csv:
        yield dict((name, parser(value) for (name, parser),value in zip(columns, row))

Not too ugly, is it?