In this program, we will take a user input as a list and remove all odd index elements from that list with the help of the below-given steps.
Remove odd index elements from a list:
Steps to solve the program
- Take a list as input.
- Create an empty list.
- Use for loop with range function to remove all odd index elements.
- Add the remaining elements to the empty list.
- Print the output to see the result.
Input list
list1 = [12, 32, 33, 5, 4, 7, 33]
#Creating an empty list
list2 = []
for i in range(len(a)):
if i%2 == 0:
list2.append(list1[i])
#printing output
print(list2)
Output :
[12, 33, 4, 33]
Related Articles
Python program to take two lists and return true if then at least one common member.
Python program to convert multiple numbers from a list into a single number.
Python program to convert words of a list into a single string.
Python program to print elements of the list separately.
Python program to create a sublist of numbers and their squares from 1 to 10.
Python program to create a list of five consecutive numbers in the list.