About 50 results
Open links in new tab
  1. python - How are lambdas useful? - Stack Overflow

    lambda x: x**2 + 2*x - 5 Those things are actually quite useful. Python supports a style of programming called functional programming where you can pass functions to other functions to do stuff. Example:

  2. python - Why use lambda functions? - Stack Overflow

    There is one downside to lambda which limits its usefulness in Python, in my opinion: lambdas can have only one expression (i.e., you can't have multiple lines). It just can't work in a language that forces …

  3. What exactly is "lambda" in Python? - Stack Overflow

    Mar 8, 2011 · Lambda is more of a concept or programming technique then anything else. Basically it's the idea that you get a function (a first-class object in python) returned as a result of another function …

  4. What is `lambda` in Python code? How does it work with `key` …

    I saw some examples using built-in functions like sorted, sum etc. that use key=lambda. What does lambda mean here? How does it work? For the general computer science concept of a lambda, see …

  5. Understanding lambda in Python and using it to pass multiple arguments

    After reading everything I can find on lambda expressions in Python, I still don't understand how to make it do what I want. Everyone uses the example: lambda x, y : x + y Why do you need to stat...

  6. python - Syntax behind sorted (key=lambda: ...) - Stack Overflow

    I don't quite understand the syntax behind the sorted() argument: key=lambda variable: variable[0] Isn't lambda arbitrary? Why is variable stated twice in what looks like a dict?

  7. Is there a way to perform "if" in python's lambda? [duplicate]

    An easy way to perform an if in lambda is by using list comprehension. You can't raise an exception in lambda, but this is a way in Python 3.x to do something close to your example:

  8. What does "lambda" mean in Python, and what's the simplest way to …

    Oct 18, 2009 · In Python it is only possible to make a lambda that returns a single expression, and the lambda cannot span multiple lines (unless you join the multiple lines by using the backslash-at-the …

  9. python - loop for inside lambda - Stack Overflow

    May 11, 2022 · 26 Since a for loop is a statement (as is print, in Python 2.x), you cannot include it in a lambda expression. Instead, you need to use the write method on sys.stdout along with the join method.

  10. sorting - How to sort with lambda in Python - Stack Overflow

    Sep 22, 2010 · 15 You're trying to use key functions with lambda functions. Python and other languages like C# or F# use lambda functions. Also, when it comes to key functions and according to the …