75. Problem to insert an element before each element of a list.

In this Python list program, we will take a user input as a list and insert an element before each element of a list with the help of the below-given steps.

Insert an element before each element in list:

Steps to solve the program
  1. Take a list as input.
  2. Add ‘a’ before each element of the list using list comprehension.
  3. Print the output to see the result.
				
					#Input list
list1 = [3, 5, 7, 8]
list1 = [text for value in list1 for 
         text in ('a', value)]

#Printing output
print(list1)
				
			

Output :

				
					['a', 3, 'a', 5, 'a', 7, 'a', 8]
				
			

Related Articles

Remove duplicate tuples from the list

Remove the duplicate string from the list

Leave a Comment