Hacker News new | past | comments | ask | show | jobs | submit login

    Python lambdas are limited to one line and can’t contain
    statements (for, if, def, etc.). Which leaves me
    wondering, what’s the point?
As much as I wish that the python lambda syntax was more powerful, they are ridiculously useful for one-liners where you can't use forms that require whitespace indentation. Everything must consist of set operations.

    cat file | python -c "import sys; lines=sys.stdin.readlines(); lines_i_care_about = [str(l.split(',')[2]) for l in lines if l.split(',')>=3]; print '\n'.join( lines_i_care_about )
(yes you could do this example in awk or sed, but that's not the point)



As others have pointed out, you could just use a non-anonymous function defined in the current scope in place of a lamba...


It's silly to use Python when sed or awk would yield better solutions.

It would be sillier to use Java. Or COBOL.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: