You can use the filter method:

>>> lst = [1, 2, 3, 4, 5]
>>> filter(lambda x: x % 2 == 0, lst)
[2, 4]

or a list comprehension:

>>> lst = [1, 2, 3, 4, 5]
>>> [x for x in lst if x %2 == 0]
[2, 4]

to find a single element, you could try:

>>> next(x for x in lst if x % 2 == 0)
2

Though that would throw an exception if nothing matches, so you'd probably want to wrap it in a try/catch. The () brackets make this a generator expression rather than a list comprehension.

Personally though I'd just use the regular filter/comprehension and take the first element (if there is one).

These raise an exception if nothing is found

filter(lambda x: x % 2 == 0, lst)[0]
[x for x in lst if x %2 == 0][0]

These return empty lists

filter(lambda x: x % 2 == 0, lst)[:1]
[x for x in lst if x %2 == 0][:1]
Answer from John Montgomery on Stack Overflow
Top answer
1 of 2
135

You can use the filter method:

>>> lst = [1, 2, 3, 4, 5]
>>> filter(lambda x: x % 2 == 0, lst)
[2, 4]

or a list comprehension:

>>> lst = [1, 2, 3, 4, 5]
>>> [x for x in lst if x %2 == 0]
[2, 4]

to find a single element, you could try:

>>> next(x for x in lst if x % 2 == 0)
2

Though that would throw an exception if nothing matches, so you'd probably want to wrap it in a try/catch. The () brackets make this a generator expression rather than a list comprehension.

Personally though I'd just use the regular filter/comprehension and take the first element (if there is one).

These raise an exception if nothing is found

filter(lambda x: x % 2 == 0, lst)[0]
[x for x in lst if x %2 == 0][0]

These return empty lists

filter(lambda x: x % 2 == 0, lst)[:1]
[x for x in lst if x %2 == 0][:1]
2 of 2
11

Generators and list comprehensions are more pythonic than chainable functions.

>>> lst = [i for i in range(1, 6)]

>>> lst
[1, 2, 3, 4, 5]

>>> gen = (x for x in lst if x % 10 == 0)

>>> next(gen, 'not_found')
'not_found'

>>> [x for x in gen]
[]

For example, I use it like this sometimes:

>>> n = next((x for x in lst if x % 10 == 0), None)
>>> if n is None:
...     print('Not found')
... 
Not found

Otherwise, you can define your utility function oneliners like this:

>>> find = lambda fun, lst: next((x for x in lst if fun(x)), None)
>>> find(lambda x: x % 10 == 0, lst)
>>> find(lambda x: x % 5 == 0, lst)
5

>>> findall = lambda fun, lst: [x for x in lst if fun(x)]
>>> findall(lambda x: x % 5 == 0, lst)
[5]
🌐
w3resource
w3resource.com › python-exercises › lambda › python-lambda-exercise-39.php
Python: Find the elements of a given list of strings that contain specific substring using lambda - w3resource
July 12, 2025 - Python Exercises, Practice and Solution: Write a Python program to find the elements of a given list of strings that contain a specific substring using lambda.
🌐
GeeksforGeeks
geeksforgeeks.org › lambda-filter-python-examples
Lambda and filter in Python Examples - GeeksforGeeks
April 8, 2025 - JavaScript doesn't have a direct equivalent to Python's lambda keyword, but it offers arrow functions that can a ... Parameters are variables defined in a function declaration. This act as placeholders for the values (arguments) that will be passed to the function. Arguments are the actual values that you pass to the function when you call it. These values replace the parameters defined in the function. Although t ... Finding the intersection of two arrays using a lambda expression and the filter() function means filtering elements from one array that exist in the other.
🌐
W3Schools
w3schools.com › python › python_lambda.asp
Python Lambda
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... A lambda function is a small anonymous function.
🌐
Stanford CS
cs.stanford.edu › people › nick › py › python-map-lambda.html
Python Map Lambda
To work with map(), the lambda should have one parameter in, representing one element from the source list. Choose a suitable name for the parameter, like n for a list of numbers, s for a list of strings. The result of map() is an "iterable" map object which mostly works like a list, but it ...
🌐
TutorialsPoint
tutorialspoint.com › python-lambda-function-to-check-if-a-value-is-in-a-list
Python - Lambda Function to Check if a value is in a List
July 18, 2023 - Map method on the other hand is an in?built method in Python which allows us to apply any specific function to all the elements of the iterable object. It takes the function and the iterable object as the parameters. In the following example we have used the 'any', 'map', and the 'lambda' function to check if a value exists in a list.
🌐
Python
python.org › search
Welcome to Python.org
The official home of the Python Programming Language
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-lambda-anonymous-functions-filter-map-reduce
Python Lambda Functions - GeeksforGeeks
DSA Python · Data Science · NumPy · Pandas · Practice · Django · Flask · Last Updated : 18 May, 2026 · Lambda functions are small anonymous functions, meaning they do not have a defined name. These are small, short-lived functions used to pass simple logic to another function.
Published   May 18, 2026
🌐
Medium
medium.com › @brentwash35 › lambda-functions-in-python-the-complete-guide-with-real-world-examples-1f1bab9f4964
Lambda Functions in Python: The Complete Guide With Real-World Examples | by Brent Ochieng | Medium
December 14, 2025 - Lambda functions allow you to write function logic in a single line, reducing visual clutter and making your code more readable when the operation is simple. Instead of defining a full function with four lines of code, you can express the same logic in one. Python supports multiple programming paradigms, including functional programming.
🌐
StrataScratch
stratascratch.com › blog › how-to-use-python-lambda-functions
How to Use Python Lambda Functions - StrataScratch
December 7, 2023 - We calculate this index by using Python lambda functions with the apply() method. It offers a detailed view of urban growth and how densely populated areas are. The Urbanization Index measures how intensely different countries are urbanizing. It combines two important factors: how fast the urban population is growing and how many people live in a given area. First, we'll find ...
🌐
freeCodeCamp
freecodecamp.org › news › lambda-functions-in-python
Lambda Functions in Python – How to Use Lambdas with Map, Filter, and Reduce
June 14, 2024 - In this tutorial, we will explore the various aspects of lambda functions in Python, including their syntax, use cases, and limitations. By understanding how to effectively utilize lambda functions, you can write more concise and efficient Python cod...
🌐
Real Python
realpython.com › python-lambda
How to Use Python Lambda Functions – Real Python
December 1, 2023 - In this step-by-step tutorial, you'll learn about Python lambda functions. You'll see how they compare with regular functions and how you can use them in accordance with best practices.
🌐
Cisco
ipcisco.com › home › python lambda
Python Lambda | Lambda & Filter Function | Lambda & Map ⋆ IpCisco
January 10, 2022 - To define a lambda function, we use “lambda” keyword firstly. After that we use the argument name. Then we use a colon and lastly, we deifne the expression. There can be one more arguments but we can use only one expression in a python lambda ...
🌐
CodeRivers
coderivers.org › blog › python-list-find-by-lambda
Python List Find by Lambda: A Comprehensive Guide - CodeRivers
February 22, 2026 - The `lambda` function, a small anonymous function, can be a powerful tool in this regard. By combining lists and `lambda` functions, we can perform efficient and concise searches. This blog post will explore how to use `lambda` to find elements in Python lists, covering basic concepts, usage ...
🌐
Finxter
blog.finxter.com › how-to-filter-in-python-using-lambda-functions
How to Filter in Python using Lambda Functions? – Be on the Right Side of Change
The lambda function lambda x: x%2 takes one argument x—the element to be checked against the filter—and returns the result of the expression x%2. This modulo expression returns 1 if the integer is odd and 0 if it is even. Thus, all odd elements pass the test.
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › python faq
How can I write a lambda to check for a particular word in a list? - Python FAQ - Codecademy Forums
June 26, 2018 - Question How can I write a lambda to check for a particular word in a list? Answer If we’re given some list of strings, like languages = ["HTML", "JavaScript", "Python", "Ruby"], we’d write a lambda where each value checked is each item in the list. From the example below, we see x being used as each number in a range() of numbers. my_list = range(16) filter(lambda x: x % 3 == 0, my_list) What we want to do here is very similar, in that our x, or whatever you want to call it, will become eac...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-lambda-function-to-check-if-value-is-in-a-list
Python - Lambda Function to Check if value is in a List - GeeksforGeeks
July 23, 2025 - Define a list with integers. Define a lambda function such that it takes array and value as arguments and check if value is present in array using in keyword
🌐
w3resource
w3resource.com › python-exercises › lambda › python-lambda-exercise-14.php
Python: Find the values of length six in a given list using Lambda - w3resource
July 12, 2025 - Python Exercises, Practice and Solution: Write a Python program to filter a given list to determine if the values in the list have a length of 6 using Lambda.