Python list are quite popular and no matter what type of field one is coding, one has to deal with lists and its various applications. In this particular article, we discuss ways to separate odd and even indexed elements and its reconstruction join. Let’s discuss ways to achieve this.

**Method #1 : Using Naive method**

Using Naive method, this task can be performed by using the loops. One can use two containers one each to store alternate elements and later joining them.

`# Python3 code to demonstrate ` `# Separating odd and even index elements ` `# using naive method ` ` ` `# initializing list ` `test_list ` `=` `[` `3` `, ` `6` `, ` `7` `, ` `8` `, ` `9` `, ` `2` `, ` `1` `, ` `5` `] ` ` ` `# printing original list ` `print` `(` `"The original list : "` `+` `str` `(test_list)) ` ` ` `# using naive method ` `# Separating odd and even index elements ` `odd_i ` `=` `[] ` `even_i ` `=` `[] ` `for` `i ` `in` `range` `(` `0` `, ` `len` `(test_list)): ` ` ` `if` `i ` `%` `2` `: ` ` ` `even_i.append(test_list[i]) ` ` ` `else` `: ` ` ` `odd_i.append(test_list[i]) ` ` ` `res ` `=` `odd_i ` `+` `even_i ` ` ` `# print result ` `print` `(` `"Seprated odd and even index list: "` `+` `str` `(res)) ` |

*chevron_right*

*filter_none*

**Output :**

The original list : [3, 6, 7, 8, 9, 2, 1, 5] Seprated odd and even index list : [3, 7, 9, 1, 6, 8, 2, 5]

**Method #2 : Using list slicing **

This particular task can be easily performed using the list slicing method in a more compact and efficient manner, this is a recommended method to solve this problem.

`# Python3 code to demonstrate ` `# Separating odd and even index elements ` `# Using list slicing ` ` ` `# initializing list ` `test_list ` `=` `[` `3` `, ` `6` `, ` `7` `, ` `8` `, ` `9` `, ` `2` `, ` `1` `, ` `5` `] ` ` ` `# printing original list ` `print` `(` `"The original list : "` `+` `str` `(test_list)) ` ` ` `# Using list slicing ` `# Separating odd and even index elements ` `res ` `=` `test_list[::` `2` `] ` `+` `test_list[` `1` `::` `2` `] ` ` ` `# print result ` `print` `(` `"Seprated odd and even index list : "` `+` `str` `(res)) ` |

*chevron_right*

*filter_none*

**Output :**

The original list : [3, 6, 7, 8, 9, 2, 1, 5] Seprated odd and even index list : [3, 7, 9, 1, 6, 8, 2, 5]

## Recommended Posts:

- Python | Convert column to separate elements in list of lists
- Python | Split dictionary keys and values into separate lists
- Dividing a Large file into Separate Modules in C/C++, Java and Python
- Python | Split and Pass list as separate parameter
- Python - Separate first word from String
- Plot multiple separate graphs for same data from one Python script
- Python | Split the Even and Odd elements into two different lists
- Python List Comprehension | Sort even-placed elements in increasing and odd-placed in decreasing order
- Python - Odd or Even elements combinations Summations in Matrix
- Sort even and odd placed elements in increasing order
- Dunn index and DB index - Cluster Validity indices | Set 1
- Python Program for Difference between sums of odd and even digits
- Python program to count Even and Odd numbers in a List
- Python - Replace index elements with elements in Other List
- Python - Check if elements index are equal for list elements
- Python Program for Odd-Even Sort / Brick Sort
- Python Program for Check if count of divisors is even or odd
- Python | N consecutive Odd or Even Numbers
- Check whether count of odd and even factors of a number are equal
- Python | Number of elements to be removed such that product of adjacent elements is always even

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.