There is an integer list, define a lambda function that will take the list and will return the count of the given element.
Python code to check if value is in a list using lambda and count() function
# Using lambda and count() function
list1 = [10, 15, 20, 15, 30]
ele = 15
# Lambda function to check an element
# in the list
countFunc = lambda list1 , ele : list1.count(ele)
count = countFunc(list1, ele)
if(count):
print("Yes, total count of", ele, "is",count)
else:
print("No")
Output:
Yes, total count of 15 is 2
Method 2: Using lambda and in keyword
There is an integer list, define a lambda function that takes the list and an element to check and returns True if element presents in the list; False, otherwise using in keyword.
Python code to check if value is in a list using lambda and in keyword
list1 = [10, 15, 20, 15, 30]
ele = 15
# Lambda function to check an element
# in the list
countFunc = lambda list1, ele: True if ele in list1 else False
if(countFunc(list1,ele)):
print("Yes")
else:
print("No")
Method 1: Using lambda and count() function
There is an integer list, define a lambda function that will take the list and will return the count of the given element.
Python code to check if value is in a list using lambda and count() function
Output:
Method 2: Using lambda and in keyword
There is an integer list, define a lambda function that takes the list and an element to check and returns True if element presents in the list; False, otherwise using in keyword.
Python code to check if value is in a list using lambda and in keyword
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer