Given a list of numbers, write a Python program to count Even and Odd numbers in a List.

Example:

Input: list1 = [2, 7, 5, 64, 14] Output: Even = 3, odd = 2 Input: list2 = [12, 14, 95, 3] Output: Even = 2, odd = 2

Example 1: count Even and Odd numbers from given list using for loop

Iterate each element in the list using for loop and check if num % 2 == 0, the condition to check even numbers. If the condition satisfies, then increase even count else increase odd count.

`# Python program to count Even ` `# and Odd numbers in a List ` ` ` `# list of numbers ` `list1 ` `=` `[` `10` `, ` `21` `, ` `4` `, ` `45` `, ` `66` `, ` `93` `, ` `1` `] ` ` ` `even_count, odd_count ` `=` `0` `, ` `0` ` ` `# iterating each number in list ` `for` `num ` `in` `list1: ` ` ` ` ` `# checking condition ` ` ` `if` `num ` `%` `2` `=` `=` `0` `: ` ` ` `even_count ` `+` `=` `1` ` ` ` ` `else` `: ` ` ` `odd_count ` `+` `=` `1` ` ` `print` `(` `"Even numbers in the list: "` `, even_count) ` `print` `(` `"Odd numbers in the list: "` `, odd_count) ` |

*chevron_right*

*filter_none*

**Output:**

Even numbers in the list: 3 Odd numbers in the list: 4

Example 2: Using while loop

`# Python program to count Even and Odd numbers in a List ` ` ` `# list of numbers ` `list1 ` `=` `[` `10` `, ` `21` `, ` `4` `, ` `45` `, ` `66` `, ` `93` `, ` `11` `] ` ` ` `even_count, odd_count ` `=` `0` `, ` `0` `num ` `=` `0` ` ` `# using while loop ` `while` `(num < ` `len` `(list1)): ` ` ` ` ` `# checking condition ` ` ` `if` `list1[num] ` `%` `2` `=` `=` `0` `: ` ` ` `even_count ` `+` `=` `1` ` ` `else` `: ` ` ` `odd_count ` `+` `=` `1` ` ` ` ` `# increment num ` ` ` `num ` `+` `=` `1` ` ` `print` `(` `"Even numbers in the list: "` `, even_count) ` `print` `(` `"Odd numbers in the list: "` `, odd_count) ` |

*chevron_right*

*filter_none*

**Output:**

Even numbers in the list: 3 Odd numbers in the list: 4

Example 3 : Using Python Lambda Expressions

`# 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) ` |

*chevron_right*

*filter_none*

**Output:**

Even numbers in the list: 3 Odd numbers in the list: 4

Example 4 : Using List Comprehension

`# Python program to print odd Numbers in a List ` ` ` `# list of numbers ` `list1 ` `=` `[` `10` `, ` `21` `, ` `4` `, ` `45` `, ` `66` `, ` `93` `, ` `11` `] ` ` ` `only_odd ` `=` `[num ` `for` `num ` `in` `list1 ` `if` `num ` `%` `2` `=` `=` `1` `] ` `odd_count ` `=` `len` `(only_odd) ` ` ` `print` `(` `"Even numbers in the list: "` `, ` `len` `(list1) ` `-` `odd_count) ` `print` `(` `"Odd numbers in the list: "` `, odd_count) ` |

*chevron_right*

*filter_none*

**Output:**

Even numbers in the list: 3 Odd numbers in the list: 4

Attention geek! Strengthen your foundations with the **Python Programming Foundation** Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the **Python DS** Course.

## Recommended Posts:

- Python Program to find Sum of Negative, Positive Even and Positive Odd numbers in a List
- Python program to find the sum of all even and odd digits of an integer list
- Python Program to Print Largest Even and Largest Odd Number in a List
- Count Odd and Even numbers in a range from L to R
- C++ program to print all Even and Odd numbers from 1 to N
- Python Program for Check if count of divisors is even or odd
- Python List Comprehension | Sort even-placed elements in increasing and odd-placed in decreasing order
- Check if count of even divisors of N is equal to count of odd divisors
- Python Program for Difference between sums of odd and even digits
- Python program to print odd numbers in a List
- Python | N consecutive Odd or Even Numbers
- Python program to print even numbers in a list
- Frequencies of even and odd numbers in a matrix
- Largest Even and Odd N-digit numbers in Hexadecimal Number System
- Python Program for Odd-Even Sort / Brick Sort
- Python Program to Determine Whether a Given Number is Even or Odd Recursively
- Count even and odd digits in an Integer
- Count number of even and odd elements in an array
- Count number of even and odd length elements in an Array
- Check whether count of odd and even factors of a number are equal

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.