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
- Take a list as input.
- Add ‘a’ before each element of the list using list comprehension.
- 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
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.
Python program to get palindrome numbers from a given list.
Python program to get a count of vowels in the given list.