Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    Why not simply result = (y, x)[a < b] Why do you uses lambda function ? Commented Dec 27, 2013 at 5:50
  • 7
    @GrijeshChauhan Because on "compliated" expressions, e. g. involving a function call etc., this would be executed in both cases. This might not be wanted. Commented Feb 13, 2014 at 8:14
  • 2
    The use of lambda functions is an overkill for this question Commented Dec 14, 2020 at 4:29
  • @GrijeshChauhan In short, this implements the so-called “short-circuit evaluation”. Generally, P ? x : y or x if P else y can be written as (lambda:y, lambda:x)[P]() — but I doubt it has better performance and thus its necessity. Commented Jan 19, 2021 at 10:11