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



In this article, we are going to learn about splitting the even and odd elements into two different lists. This involves looping each element in a list and checking whether it is divisible by 2. Even numbers are those that gives the remainder '0' when divided by 2, while the odd numbers leaves a remainder '1'.

Using Python append() Method

The Python append() method is used to add the new object to a list. It accepts an object as a argument and inserts it at the end of the existing list.

Syntax

Following is the syntax of Python append() method -

list.append(obj)

In this approach, we are going to initialize the 3 lists, in which one is filled with number, then we use the conditional expression to check whether it is divisible by 2. if it divisible then it is added to the list which is specified for even numbers by using the append() method.

Example

Let's look at the following example, where we are going to split even numbers and odd numbers from the list [1,22,3,44].

lst = [1,22,3,44]
x = []
y = []
for num in lst:
    if num % 2 == 0:
        x.append(num)
    else:
        y.append(num)
print("Even numbers:", x)
print("Odd numbers:", y)

The output of the above program is as follows -

Even numbers: [22, 44]
Odd numbers: [1, 3]

Using List Comprehension

The python List comprehension offers a simple way to create a lists using a single line of code. It combines loops and conditional statements making it efficient compared to the traditional methods of list construction.

Syntax

Following is the syntax of python list comprehension -

newlist = [expression for item in iterable if condition == True]

In this scenario, we are going to use the list comprehension, for constructing the even and odd numbers in two separate lists by passing the expression with the given input.

Example

Consider the following example, where we are going to use the list comprehension and splitting the even and odd elements into two different lists.

lst = [11,2,33,4,55]
x = [num for num in lst if num % 2 == 0]
y = [num for num in lst if num % 2 != 0]
print("Even numbers:", x)
print("Odd numbers:", y)

The output of the above program is as follows -

Even numbers: [2, 4]
Odd numbers: [11, 33, 55]
Updated on: 2025-08-28T13:45:35+05:30

24K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements