Python Practice › List Programs › Program 47

Add a prefix to every item

EasyList Programs · 47 of 100

Write a Python program to insert a string at the beginning of every item.

Advertisement
Input
[1, 2, 3, 4, 5], "Sqa"
Output
['Sqa1', 'Sqa2', 'Sqa3', 'Sqa4', 'Sqa5']

Approach

  1. An f-string for each item.

Solution

Python
print([f"Sqa{n}" for n in [1, 2, 3, 4, 5]])
Output
['Sqa1', 'Sqa2', 'Sqa3', 'Sqa4', 'Sqa5']
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More list programs

← All 100 List Programs