Search
 
SCRIPT & CODE EXAMPLE
 

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)
Comment

PREVIOUS NEXT
Code Example
Python :: pandas dataframe display cell size 
Python :: perform_update serializer django 
Python :: how to rename columns in pandas dataframe 
Python :: discord.py send message to user id 
Python :: string in list py 
Python :: python list replace nan with 0 
Python :: python dict keys to string 
Python :: seaborn color palette python 
Python :: log log grid python 
Python :: sum of prime numbers python 
Python :: remote python running line by line visual code 
Python :: python print date, time and timezone 
Python :: convert datetime to date pandas 
Python :: pip install pandas Getting requirements to build wheel 
Python :: attr module python 
Python :: python .format 
Python :: python rotate list 
Python :: if else python 
Python :: def python 
Python :: append multiple values to 2d list python 
Python :: install pocketsphinx error 
Python :: confusion matrix with labels sklearn 
Python :: print(int()) 
Python :: convert 2 level nested list to one level list in python 
Python :: Converting Dataframe from list Using a list in the dictionary 
Python :: how to create pyw file 
Python :: Creating Python Sets 
Python :: balancing paranthesis python 
Python :: python frozenset() 
Python :: pandas drop duplicates but keep most recent date 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =