About 197,000 results
Open links in new tab
  1. What is `lambda` in Python code? How does it work with `key` …

    It's worth mentioning that there's no reason to ever name a lambda when you can use a def instead. In this answer it's only being used for demonstration. In Python, lambda is a keyword used to define …

  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. 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:

  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. 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:

  7. 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?

  8. python - List comprehension vs. lambda + filter - Stack Overflow

    I find the list comprehension much clearer than filter + lambda, but use whichever you find easier. There are two things that may slow down your use of filter. The first is the function call overhead: as soon …

  9. python max function using 'key' and lambda expression

    Aug 18, 2013 · I come from OOP background and trying to learn python. I am using the max function which uses a lambda expression to return the instance of type Player having maximum totalScore …

  10. python - Can you assign variables in a lambda? - Stack Overflow

    I was using a lambda statement to perform math, and happened to repeatedly use one certain value. Therefore I was wondering if it was possible to assign and use a variable within a lambda statement...