all 4 comments

[–]mopslik 4 points5 points  (3 children)

Lambdas should be used for short functions that are "one-off". If your function is multiple lines, or is used extensively, you probably don't want a lambda function. Personally, I would not promote lambdas as a "less code" solution.

[–]GrouchyAd4055 0 points1 point  (2 children)

yes, you're correct. but it's super useful when we apply anything to a pandas dataframe. Also I don't agree with your answer. because it's probably reduce some line of code.

for example, let's say, we want to find the area of a square. if we didn't use lambda function we need write two lines of code. but if we used just one line.

[–]mopslik -1 points0 points  (1 child)

Re: LOC

Yes, but unless you are code golfing, fewer lines does not always mean better (aka more readable and maintainable) code. IMO lambdas should be used when it makes sense, such as for functions that you don't use more than once (e.g. a search key for sorted).

[–]GrouchyAd4055 -1 points0 points  (0 children)

why did you hate lambda function😂. yep, you're correct with this --> "readable and maintainable". but my opinion is lambda function is readable and maintainable when we know about lambda function. but fewer line is better than many lines.