Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python program to count Even and Odd numbers using lambda

# list of numbers
list1 = [10, 21, 4, 45, 66, 93, 11]
  
odd_count = len(list(filter(lambda x: (x%2 != 0) , list1)))
  
# we can also do len(list1) - odd_count
even_count = len(list(filter(lambda x: (x%2 == 0) , list1)))
  
print("Even numbers in the list: ", even_count)
print("Odd numbers in the list: ", odd_count)
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Python #program #count #Even #Odd #numbers #lambda
ADD COMMENT
Topic
Name
2+4 =