73. Problem to create a list by taking an alternate item.

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
  1. Take a list as input.
  2. Create a new list that will contain alternate elements from the given list.
  3. Use for loop with range function for this purpose.
  4. 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

Remove duplicate sublists from the list

Remove duplicate tuples from the list

Leave a Comment