How about:

>>> any(isinstance(e, int) and e > 0 for e in [1,2,'joe'])
True

It also works with all() of course:

>>> all(isinstance(e, int) and e > 0 for e in [1,2,'joe'])
False
Answer from Antoine P. on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_lambda.asp
Python Lambda
Python Examples Python Compiler ... Interview Q&A Python Bootcamp Python Certificate Python Training ... A lambda function is a small anonymous function....
๐ŸŒ
Real Python
realpython.com โ€บ python-lambda
How to Use Python Lambda Functions โ€“ Real Python
December 1, 2023 - You need to invoke list() to convert the iterator returned by map() into an expanded list that can be displayed in the Python shell interpreter. Using a list comprehension eliminates the need for defining and invoking the lambda function: ... The built-in function filter(), another classic functional construct, can be converted into a list comprehension. It takes a predicate as a first argument and an iterable as a second argument. It builds an iterator containing all the elements of the initial collection that satisfies the predicate function.
Discussions

functional programming - any() function in Python with a callback - Stack Overflow
Thanks for calling out the generator ... like a lambda version (in terms of not having to process the entire list if an earlier item is false). Also, nice to know we can leave off parens of a generator if it is the only parameter. Somehow missed that.. 2013-11-08T20:23:01.083Z+00:00 ... While the others gave good Pythonic answers (I'd ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to create a list of different lambda functions.
[(lambda x, i=i: x*i) for i in range(3)] https://docs.python.org/3/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result More on reddit.com
๐ŸŒ r/learnpython
13
70
January 5, 2021
Lambda function
map applies a function to every element of an iterable. Sometimes these functions are very simple operations; for example, if I wanted to double every number in a list. It's wasteful to define an entire new function (with the def keyword) just for this one simple operation. Lambda creates a callable function that we can use. Here's an example of how we could create that and use it with map. numbers = [1, 5, 20, 50] map(lambda x:x * 2, numbers) More on reddit.com
๐ŸŒ r/learnpython
24
11
September 15, 2023
python - using lambda to verify all elements in list - Stack Overflow
i have a list of foods called "my_foods". i would like to use a lambda function to verify that all elements from the list "good_foods" appear in the list "my_foods", and also verify that none of ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-lambda-anonymous-functions-filter-map-reduce
Python Lambda Functions - GeeksforGeeks
In this example, a lambda function is defined to convert a string to its upper case using upper(). ... In Python, lambda functions are created using the lambda keyword.
Published ย  4 days ago
๐ŸŒ
The Python Coding Stack
thepythoncodingstack.com โ€บ p โ€บ whats-all-the-fuss-about-python-lambda-functions
What's All the Fuss About `lambda` Functions in Python
December 1, 2023 - Python's lambda functions are functions with no name and which have a single expression. They're "disposable" functions. You create them as and when you need them, and then they're gone.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-lambda-functions
Python Lambda Functions โ€“ How to Use Anonymous Functions with Examples
February 24, 2023 - Lambda functions, also known as anonymous functions, are small, one-time-use functions in Python. You can define them using the lambda keyword followed by the function's inputs, a colon, and the function's expression.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ anonymous-function
Python Lambda/ Function (With Examples)
Finally, the statement inside the lambda function is executed. ... The filter() function in Python takes in a function and an iterable (lists, tuples, and strings) as arguments. The function is called with all the items in the list, and a new list is returned, which contains items for which ...
Find elsewhere
๐ŸŒ
Amazon Web Services
docs.aws.amazon.com โ€บ aws lambda โ€บ developer guide โ€บ building lambda functions with python
Building Lambda functions with Python - AWS Lambda
You can run Python code in AWS Lambda. Lambda provides runtimes for Python that run your code to process events. Your code runs in an environment that includes the SDK for Python (Boto3), with credentials from an AWS Identity and Access Management (IAM) role that you manage.
๐ŸŒ
Stanford CS
cs.stanford.edu โ€บ people โ€บ nick โ€บ py โ€บ python-map-lambda.html
Python Map Lambda
double each n [2, 4, 6, 8, 10] >>> >>> list(map(lambda n: n * -1, nums)) [-1, -2, -3, -4, -5] >>> >>> list(map(lambda n: 2 ** n, nums)) [2, 4, 8, 16, 32] >>> >>> strs = ['Summer', 'is', 'coming'] >>> list(map(lambda s: s.upper() + '!', strs)) ['SUMMER!', 'IS!', 'COMING!']
๐ŸŒ
Python Engineer
python-engineer.com โ€บ courses โ€บ advancedpython โ€บ 08-lambda
Lambda Functions - Advanced Python 08 - Python Engineer
A lambda function is a small (one line) anonymous function that is defined without a name. A lambda function can take any number of arguments, but can only have one expression. While normal functions are defined using the def keyword, in Python ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-lambda-function-explained
How the Python Lambda Function Works โ€“ Explained with Examples
December 17, 2024 - You can manipulate all of the values in a series by using the lambda function. For example, if I have a data frame with the following columns and want to convert the values in the name column to lower case, I can do so using the Pandas apply function and a Python lambda function like this:
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ lambda function
r/learnpython on Reddit: Lambda function
September 15, 2023 -

I understand what the lambda function is, its an anonymous function in one line, however why using it, and what really is it? I mean every code I looked at, has it and don't forget map() reduce and filter() function are used with it, what are all these used for and why, I did my research but I still don't understand, (I have a baby's brain ๐Ÿง  y'all)

๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-lambda-functions
Python Lambda Functions: A Beginnerโ€™s Guide | DataCamp
January 31, 2025 - You could write a standard Python function, but the same functionality can be achieved with a concise one-liner lambda function assigned to a variable: is_even = lambda x: x % 2 == 0. Here, the lambda function on the right side of the assignment takes an input x and returns True if x is even (that is if the remainder when divided by 2 is 0). This lambda function is then assigned to the variable is_even, allowing ...
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Lambda Expressions in Python | note.nkmk.me
August 19, 2023 - Filter (extract/remove) items of a list with filter() in Python ยท When specifying a function (callable object) as an argument, using a lambda expression is often simpler than defining the function with a def statement. Note that operations similar to map() and filter() can also be written using list comprehensions and generator expressions, which are often easier to use in many cases. ... Specify a lambda expression that squares the value as the first argument.
๐ŸŒ
Dataquest
dataquest.io โ€บ blog โ€บ tutorial-lambda-functions-in-python
Tutorial: Lambda Functions in Python
March 6, 2023 - So, if we really need to store ... a lambda function to a variable, we'd better define an equivalent normal function. We use the filter() function in Python to select certain items from an iterable (like lists, sets, tuples, Series, etc.) based on predefined criteria. It takes two arguments: ... To get a new iterable from the filter object, with all the items ...
๐ŸŒ
Python
python.org โ€บ search
Welcome to Python.org
The official home of the Python Programming Language
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ lambda-expression-python
Python Lambda Expressions Explained with Examples | DigitalOcean
July 8, 2025 - Hereโ€™s an example of using lambda with reduce to sum all elements in a list: from functools import reduce numbers = [1, 2, 3, 4, 5] sum_of_numbers = reduce(lambda x, y: x + y, numbers) print(sum_of_numbers) # Output: 15 ... Nested lambda functions in Python are lambda functions that are defined inside other lambda functions.
Top answer
1 of 5
2
good_foods = ['apple', 'carrot']
junk_foods = ['soda', 'burger']

my_foods = ['banana', 'carrot', 'bread', 'apple', 'soda']

result = all( map( lambda x: x in my_foods, good_foods ) ) and 
         not( any( map( lambda x: x in junk_foods, my_foods ) ) ) 
2 of 5
2

I would solve this problem using any() and all() like so:

result = (all(f in my_foods for f in good_foods) and
    not any(f in my_foods for f in junk_foods))

If you really want to use lambda for this, you can do it:

lambda my f: f in my_foods
lambda bad f: f in junk_foods

result = all(my(f) for f in good_foods) and not any(bad(f) for f in my_foods)

But I would do the above with real functions:

def my(f):
    return f in my_foods

def bad(f):
    return f in junk_foods

result = all(my(f) for f in good_foods) and not any(bad(f) for f in my_foods)

Now, if you really wanted to do this with lambda using map() or reduce(), here is my suggestion:

result = (reduce(lambda x, y: x and y, map(lambda f: f in my_foods, good_foods))
    and reduce(lambda x, y: x and y, map(lambda f: f not in junk_foods, my_foods)))

I think the above is slightly improved if we take advantage of the built-in bool.__and__() function, which implements logical and on Booleans, like so:

result = (reduce(bool.__and__, map(lambda f: f in my_foods, good_foods))
    and reduce(bool.__and__, map(lambda f: f not in junk_foods, my_foods)))

But here's a solution using filter() if you prefer that. filter() strips out elements that fail a test, so the easiest way to find out if every element passes the test is to see if the resulting list is the same length as the original list.

result = (len(filter(lambda f: f in my_foods, good_foods)) == len(good_foods) and
    len(filter(lambda f: f not in junk_foods, my_foods)) == len(my_foods))

Note that any() and all() both have "short-circuit" evaluation; they will be faster than reduce() in cases where not every element in the list really needs to be examined. For example, if the first item in the list is in the junk_foods list, the any() test will immediately complete and the not any(...) will evaluate to False. The reduce() answer would still go through the whole junk_foods list.

Also note that for large lists, you will gain a big speed improvement by using sets. Some of the other answers suggest converting the lists to sets and using set features; this is probably the best way to go.