- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to split the even and odd elements into two different lists.
In this program we create a user input list and the elements are mixture of odd and even elements. Our task is to split these list into two list. One contains odd number of element and another is even number of elements.
Example
Input: [1, 2, 3, 4, 5, 9, 8, 6] Output Even lists: [2, 4, 8, 6] Odd lists: [1, 3, 5, 9]
Algorithm
Step 1 : create a user input list. Step 2 : take two empty list one for odd and another for even. Step 3 : then traverse each element in the main list. Step 4 : every element is divided by 2, if remainder is 0 then it’s even number and add to the even list, otherwise its odd number and add to the odd list.
Example Code
# Python code to split into even and odd lists # Funtion to split def splitevenodd(A): evenlist = [] oddlist = [] for i in A: if (i % 2 == 0): evenlist.append(i) else: oddlist.append(i) print("Even lists:", evenlist) print("Odd lists:", oddlist) # Driver Code A=list() n=int(input("Enter the size of the First List ::")) print("Enter the Element of First List ::") for i in range(int(n)): k=int(input("")) A.append(k) splitevenodd(A)
Output
Enter the size of the First List :: 8 Enter the Element of First List :: 1 2 3 4 5 9 8 6 Even lists: [2, 4, 8, 6] Odd lists: [1, 3, 5, 9]
- Related Articles
- Java program to split the Even and Odd elements into two different lists
- Python Program to Put Even and Odd elements in a List into Two Different Lists
- C# program to split the Even and Odd integers into different arrays
- Separate Odd and Even Elements into Two Separate Arrays in Java
- Swap Even Index Elements And Odd Index Elements in Python
- Python program to print all the common elements of two lists.
- C program to store even, odd and prime numbers into separate files
- Program to split lists into strictly increasing sublists of size greater than k in Python
- Adding two Python lists elements
- Program to interleave list elements from two linked lists in Python
- Program to find number of elements can be removed to make odd and even indexed elements sum equal in Python
- Program to find minimum difference between two elements from two lists in Python
- Sorting odd and even elements separately JavaScript
- Python program to Count Even and Odd numbers in a List
- Python Program to Merge Two Lists and Sort it

Advertisements