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
- Take a list as input and create two empty lists.
- Add even and odd elements from the given list into the empty list with the help of for loop.
- Combine odd element list with even element list using extend().
- 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
Python program to get common elements from two lists.
Python program to reverse a list with for loop.
Python program to reverse a list with a while loop.
Python program to reverse a list using index slicing.
Python program to reverse a list with reversed and reverse methods.
Python program to copy or clone one list to another list.