47. Problem to insert a given string at the beginning of list elements.

In this Python list program, we will take a user input as a list and insert the given string at the beginning of the list elements with the help of the below-given steps.

Insert a string at the beginning of list elements:

Steps to solve the program
  1. Take a list as input.
  2. Add ‘sqa’ at the beginning of every element of the list.
  3. Use the list comprehension method for this purpose.
  4. Use for loop to iterate over elements in the list.
  5. During the loop add ‘Sqa’ to each element using the .format() method.
  6. Print the output to see the result.
				
					#Input list
list1 = [1, 2, 3, 4, 5]

#Printing output
print(['Sqa{0}'.format(value) for value in  list1])
				
			

Output :

				
					['Sqa1', 'Sqa2', 'Sqa3', 'Sqa4', 'Sqa5']
				
			

Related Articles

Create a list of five consecutive numbers

Iterate over lists and create a list of sublists

Leave a Comment