Python: Insert an element before each element of a list
Insert Element Before Each List Item
Write a Python program to insert an element before each element of a list.
Sample Solution:
Python Code:
Sample Output:
Original List: ['Red', 'Green', 'Black'] Updated List: ['c', 'Red', 'c', 'Green', 'c', 'Black']
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Python program to insert a given value before every element in a list dynamically.
- Write a Python program to add a prefix to every string in a list.
- Write a Python program to insert a value at every nth position in a list.
- Write a Python program to duplicate each element in a list and insert a separator between them.
Go to:
Previous: Write a Python program to select the odd items of a list.
Next: Write a Python program to print a nested lists (each list on a new line) using the print() function.
Python Code Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.