Python | Split the Even and Odd elements into two different lists
In this program, a list is accepted with the mixture of odd and even elements and based on whether the element is even or odd, it is split into two different lists.
Examples:
Input : [8, 12, 15, 9, 3, 11, 26, 23]
Output : Even lists: [8, 12, 26]
Odd lists: [15, 9, 3, 11, 23]
Input : [2, 5, 13, 17, 51, 62, 73, 84, 95]
Output : Even lists: [2, 62, 84]
Odd lists: [5, 13, 17, 51, 73, 95]
# Python code to split into even and odd lists # Funtion to split def Split(mix): ev_li = [] od_li = [] for i in mix: if (i % 2 == 0): ev_li.append(i) else: od_li.append(i) print("Even lists:", ev_li) print("Odd lists:", od_li) # Driver Code mix = [2, 5, 13, 17, 51, 62, 73, 84, 95] Split(mix) |
chevron_right
filter_none
Output:
Even lists: [2, 62, 84] Odd lists: [5, 13, 17, 51, 73, 95]
Recommended Posts:
- Python | Split list into lists by particular value
- Python | Split nested list into two lists
- Python | Split dictionary of lists to list of dictionaries
- Python | Split dictionary keys and values into separate lists
- Python | Split K elements after every N values
- Python | Split strings in list with same prefix in all elements
- Python | Pandas Split strings into two List/Columns using str.split()
- Python | Get positive elements from given list of lists
- Python | Print all the common elements of two lists
- Python | Find common elements in list of lists
- Python program to find common elements in three lists using sets
- Python | Convert column to separate elements in list of lists
- Python | Sorting list of lists with similar list elements
- Python | Program to count number of lists in a list of lists
- Python | Maximum sum of elements of list in a list of lists
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



