Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Lambda is quite clunky. A lot is possible by abusing tuples and walrus assignment, which Ive on occasion used for one liners. e.g. you want to execute a function for each element of a list (print is a function in py3) so mapping over a generator with eg

    map(lambda x: (x := func1(x), func2(x), None)[2], gen())
This sets x to func1(x), then executes func2, then leaves None in place of the element in the map iterable. (of course you could do the same with a list comprehension, you wouldn't even need the lambda in that case, and good python would _actually_ be a for loop.)


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

Search: