Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

separete even and odd numbers from a list by filter in python

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 45, 89, 63, 74, 85, 96, ]
even = list(filter(lambda x: x % 2 == 0, numbers))
ec = len(even)
print("Even numbers:", even)
print("Total even numbers =", ec)

odd = list(filter(lambda x: x % 2 != 0, numbers))
oc = len(odd)
print("Odd numbers:", odd)
print("Total odd numbers =", oc)

 
PREVIOUS NEXT
Tagged: #separete #odd #numbers #list #filter #python
ADD COMMENT
Topic
Name
1+1 =