In this Python list program, we will take a user input as a list and create a new list by taking an alternate item from the list with the help of the below-given steps.
Create a list with alternate items:
Steps to solve the program
- Take a list as input.
- Create a new list that will contain alternate elements from the given list.
- Use for loop with range function for this purpose.
- Print the new list to see the output.
#Input lists
list1 = [3, 5, 7, 8, 2, 9, 3, 5, 11]
list2 = []
for i in range(0,len(list1),2):
list2.append(list1[i])
#Prinitng output
print(list2)
Output :
[3, 7, 2, 3, 11]
Related Articles
Python program to remove duplicate tuples from the list.
Python program to insert an element before each element of a list.
Python program to remove the duplicate string from the list.
Python program to get the factorial of each item in the list.
Python program to get a list of Fibonacci numbers from 1 to 20.
Python program to reverse all the numbers in a given list.