There are several different answers I can give here, from your specific question to more general concerns. So from most specific to most general:

Q. Can you put multiple statements in a lambda?

A. No. But you don't actually need to use a lambda. You can put the statements in a def instead. i.e.:

def second_lowest(l):
    l.sort()
    return l[1]

map(second_lowest, lst)

Q. Can you get the second lowest item from a lambda by sorting the list?

A. Yes. As alex's answer points out, sorted() is a version of sort that creates a new list, rather than sorting in-place, and can be chained. Note that this is probably what you should be using - it's bad practice for your map to have side effects on the original list.

Q. How should I get the second lowest item from each list in a sequence of lists?

A. sorted(l)[1] is not actually the best way for this. It has O(N log(N)) complexity, while an O(n) solution exists. This can be found in the heapq module.

>>> import  heapq
>>> l = [5,2,6,8,3,5]
>>> heapq.nsmallest(l, 2)
[2, 3]

So just use:

map(lambda x: heapq.nsmallest(x,2)[1],  list_of_lists)

It's also usually considered clearer to use a list comprehension, which avoids the lambda altogether:

[heapq.nsmallest(x,2)[1] for x in list_of_lists]
Answer from Brian on Stack Overflow
People also ask

Can a lambda expression truly contain multiple statements?
A: No, lambda expressions in Python can only contain a single expression, but you can exploit various techniques to simulate the functionality of multiple statements.
🌐
sqlpey.com
sqlpey.com › python › top-10-ways-to-solve-can-python-lambda-expressions-contain-multiple-statements
Top 10 Ways to Solve: Can Python Lambda Expressions Contain Multiple ...
What are some common uses of lambda expressions?
A: Lambda functions are commonly used for short callbacks or as arguments to higher-order functions like map, filter, or reduce where creating a full function definition is unnecessary.
🌐
sqlpey.com
sqlpey.com › python › top-10-ways-to-solve-can-python-lambda-expressions-contain-multiple-statements
Top 10 Ways to Solve: Can Python Lambda Expressions Contain Multiple ...
Why can't I use the `sort` method directly in a lambda?
A: The sort() method sorts a list in place and returns None, which prevents you from using its return value directly in a lambda expression.
🌐
sqlpey.com
sqlpey.com › python › top-10-ways-to-solve-can-python-lambda-expressions-contain-multiple-statements
Top 10 Ways to Solve: Can Python Lambda Expressions Contain Multiple ...
🌐
Stack Overflow
stackoverflow.com › questions › 40883527 › how-to-write-multiple-statements-in-lambda-expression-body-in-jsp-el
How to write multiple statements in lambda expression body in JSP EL - Stack Overflow
Write it in round braces and separate the statements by comma. The return value must be the last sub-expression. For example: ${ factorial = n -> (print();n==0?1:n*factorial(n-1)); factorial(5); } ... Sign up to request clarification or add ...
🌐
sqlpey
sqlpey.com › python › top-10-ways-to-solve-can-python-lambda-expressions-contain-multiple-statements
Top 10 Ways to Solve: Can Python Lambda Expressions Contain Multiple Statements?
November 6, 2024 - A: No, lambda expressions in Python can only contain a single expression, but you can exploit various techniques to simulate the functionality of multiple statements.
🌐
Splunk
help.splunk.com › en › splunk-cloud-platform › search › spl2-search-manual › expressions-and-predicates › lambda-expressions
Lambda expressions | Splunk Enterprise, Splunk Cloud Platform (last updated 2026-07-27T18:10:48.930Z)
This example uses a lambda expression where $r represents the current element in the array. ... To specify multiple function statements in your lambda expression, you must separate each statement with a semi-colon ( ; ).
Find elsewhere
🌐
Iditect
iditect.com › faq › python › how-to-have-multiple-statements-in-a-python-lambda-expression.html
How to have multiple statements in a python lambda expression?
However, you can simulate multiple statements in a lambda expression by using a semicolon (;) to separate expressions. Each expression will be executed sequentially, but only the result of the last expression will be returned.
🌐
Rip Tutorial
riptutorial.com › put multiple statements in a statement lambda
C# Language Tutorial => Put Multiple Statements in a Statement Lambda
Unlike an expression lambda, a statement lambda can contain multiple statements separated by semicolons.
🌐
Real Python
realpython.com › lessons › multiple-expressions-lambda
Multiple Expressions in lambda (Video) – Real Python
03:23 And so if I call lambda_func(), Python knows that it’s expecting two parameters. The first one I’ll say "Hello", and the second one I’ll say "World". 03:40 And it worked! What happened here? Well, it takes advantage of the fact that the print statement returns None when it needs to have its value determined and that None is interpreted as a False value. 04:02 So, we have this or statement, which needs to be evaluated. Python evaluates the left expression first.
Published: May 18, 2021
🌐
Verve AI
vervecopilot.com › interview-questions › what-are-the-hidden-rules-of-a-multiline-lambda-function-python-in-technical-interviews
What Are The Hidden Rules Of A Multiline Lambda Function Python In… · Function Python In Technical Interv… · Interview Q&A | Verve AI
It cannot contain multiple statements, assignments, `if`/`else` blocks as statements, or explicit `return` statements [^2]. This is where the confusion about a multiline lambda function Python often begins.
🌐
pythontutorials
pythontutorials.net › blog › is-it-possible-to-have-multiple-statements-in-a-python-lambda-expression
Is Multiple Statements in Python Lambda Possible? Solving the Second Smallest Number in Sublists — pythontutorials.net
By design, lambda functions are restricted to a single expression. They cannot contain multiple statements (e.g., assignments, loops, if-else blocks with colons, or function definitions).
🌐
Kodeclik
kodeclik.com › python-multiline-lambda
Can you write a multiline lambda in Python?
September 19, 2024 - Lambda functions are expected to be short and sweet and just contain one expression in their definition.You can split a single line lambda over multiple lines but you technically cannot write a lambda function that is more than a single expression.
🌐
TutorialsTeacher
tutorialsteacher.com › linq › linq-lambda-expression
Anatomy of the Lambda Expression
It is not necessary to have atleast one parameter in a lambda expression. The lambda expression can be specify without any parameter also. ... (s, youngAge) => <b>{</b> Console.WriteLine("Lambda expression with multiple statements in the body"); ...
🌐
CSDN
devpress.csdn.net › python › 62fd2c36c677032930802e61.html
Is it possible to have multiple statements in a python lambda expression?_python_Mangs-Python
August 18, 2022 - It's also usually considered clearer to use a list comprehension, which avoids the lambda altogether:
🌐
TutorialsPoint
tutorialspoint.com › article › how-can-we-write-a-multiline-lambda-expression-in-java
How can we write a multiline lambda expression in Java?
([comma seperated argument-list]) -> { multiline statements } interface Employee { String displayName(String s); } public class MultilineLambdaTest { public static void main(String[] s) { Employee emp = <strong>(x) -> {</strong> // Lambda Expression with multiple lines x = "Jai " + x; System.out.println(x); return x; }; emp.displayName("Adithya"); } }
🌐
Verve AI
vervecopilot.com › interview-questions › why-understanding-lambda-multiline-python-is-crucial-for-technical-interviews
Why Understanding Lambda Multiline Python Is Crucial For Technical… · Is Crucial For Technical Interviews · Interview Q&A | Verve AI
While the term "multiline" might suggest multiple statements or a complex function body, Python's lambda functions are strictly limited to a single expression [^3]. You cannot include multiple statements like `if/else` blocks, `for` loops, or ...