VOOZH about

URL: https://www.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


  • Courses
  • Tutorials
  • Interview Prep

Python - Lambda Function to Check if value is in a List

Last Updated : 23 Jul, 2025

Given a list, the task is to write a Python program to check if the value exists in the list or not using the lambda function.

Example:

Input :  L = [1, 2, 3, 4, 5]
 element = 4
Output : Element is Present in the list

Input  : L = [1, 2, 3, 4, 5]
 element = 8
Output : Element is NOT Present in the list

We can achieve the above functionality using the following two methods.

Method 1: Using Lambda and Count() method

Define a list with integers. Define a lambda function such that it takes array and value as arguments and return the count of value in list.

lambda v:l.count(v)

If the count is zero then print the Element is not present else print element is NOT present.

Output:

Element is Present in the list

Explanation:  The arr and v are passed to the lambda function and it evaluates the count of v in the arr and here v = 3 and it is present 1 time in the array and the if condition is satisfied and prints the element Is present in the list.

Method 2: Using Lambda and in keyword

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

lambda v: True if v in l else False

If the lambda return True then print the Element is present else print element is NOT present.

Output:

Element is Not Present in the list

Explanation:  The arr and v are passed to the lambda function and it checks if the value is present in an array using IN keyword and here v = 8 and it is NOT Present in the array and returns false so prints the element Is NOT present in the list.

Comment
Article Tags: