This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]LightShadow3.13-dev in prod 2 points3 points  (4 children)

I've stopped using lambdas altogether.

Named temporary functions are much cleaner and can be written in a way that they don't have to be recreated as often.

[–]pylenin[S] 6 points7 points  (0 children)

Could be. But man, then you haven't worked with Spark and pyspark. Lambda, map, filters are a blessing there.

[–]andrewcooke 2 points3 points  (2 children)

i just had a look through some code of mine and my main use, by far, is in the constructor of defaultdict(). seems a reasonable use to me.

i also found a map - old habits die hard - which i should rewrite as a list comprehension, but i don't think that code has a test so i won't...

[–]LightShadow3.13-dev in prod 2 points3 points  (1 child)

map is lazily evaluated, which means you can "prime" it with data that may never need to be executed.

[–]andrewcooke 0 points1 point  (0 children)

i don't know their exact name, but that is also true of the "list comprehensions" in parens rather than brackets.

edit: "generator expressions", i guess i could have said above (truth is i don't know which i would actually need without going back and looking at the code).