Articles

Program to create a new list with elements present at odd position of the given list in Python

Program to create a new list with elements present at odd position of the given list in Python


In the python programming article, we are going to learn

  • program to make a new list with all the elements at odd position from a given list in python

Program to make a new list with all the elements at odd position from a given list in Python

Here we will learn how to create a new list from an existing list in python?

 

We are going to create a new list with elements present at odd position of the given list in Python. The program to make a new list with all the elements at odd position from a given list is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

numbers = [22,11,34,56,78,61,35,91,77,59]

new_list = list()

for i in range(len(numbers)):
    if i % 2 != 0:
        new_list.append(numbers[i])
    else:
        pass

print("The new list is:")
for i in new_list:
    print(i,end = " ")
        

The output of the program is as follows:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
The new list is:
11 56 61 91 59

Few important tips about the program

1. In the given program, we iterate over the length of the given list and check for the odd positions.

2. For the odd positions, we take out the data from the given list and append it to the new list.

 

how to create a new list from an existing list in python?

make a new list with elements from odd positions of a given list

By using above logic you can create any new list in python. This wraps up our session on how to create a new list from an existing list in python.


Python Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Data Science Enthusiast
Page Views :    Published Date : Aug 08,2022  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!