10. Problem to split the list into two-part.

In this program, we will take a user input as a list and split the list into two-part, the left side all odd values and the right side all even values i.e. split the list with the help of the below-given steps.

Split the list:

Steps to solve the program
  1. Take a list as input and create two empty lists.
  2. Add even and odd elements from the given list into the empty list with the help of for loop.
  3. Combine odd element list with even element list using extend().
  4. Print the output.
				
					#Input list
list1 = [5, 7, 2, 8, 11, 12, 17, 19, 22]

#Creating empty list
even = []
odd = []

for value in list1:
    if value%2 == 0:
        even.append(value)
    else:
        odd.append(value)

#Combining lists
odd.extend(even)

#printing output
print(odd)
				
			

Output :

				
					[5, 7, 11, 17, 19, 2, 8, 12, 22]
				
			

Related Articles

Squares of all even numbers

Get common elements from two lists.

Leave a Comment