Python program to split the even and odd elements into two different lists

Python program to split the even and odd elements into two different lists

In this tutorial, we will learn how to split the even and odd numbers into two different lists. The first list is used to separate even numbers and the second is for odd.

Explanation ✏

  1. Create a list of numbers (even and odd both)

  2. Now using for loop, iterate the whole list and with the help of the if/else condition check whether the number is even or odd.

  3. If the number is even ( i%2 == 0 ), then append that number to the even number list and if the number is odd, append to the odd list.

  4. And finally, print both even and odd list

Code 👩‍💻

def evenNodd(num):
    evenList,oddList = [],[]
    for i in num:
        if i % 2 == 0:
            evenList += [i]
        else:
            oddList += [i]
    print("Even Numbers: ",evenList)
    print("Odd Numbers: ",oddList)
evenNodd([10,15,20,25,30,35])

Output : Even Numbers: [10, 20, 30] Odd Numbers: [15, 25, 35]