40. Problem to remove all odd index elements.

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
  1. Take a list as input.
  2. Create an empty list.
  3. Use for loop with range function to remove all odd index elements.
  4. Add the remaining elements to the empty list.
  5. 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

Check the given element exists in the list

Return true if one common member in lists

Leave a Comment