Python Practice › Tuple Programs › Program 55

Insert a string after every element

EasyTuple Programs · 55 of 70

Write a Python program to convert a tuple into a list with a string after every element.

Advertisement
Input
(1, 2, 3, 4), "sqatools"
Output
[1, 'sqatools', 2, 'sqatools', 3, 'sqatools', 4, 'sqatools']

Approach

  1. For each item add the item and the string.

Solution

Python
t = (1, 2, 3, 4)word = "sqatools"print([x for item in t for x in (item, word)])
Output
[1, 'sqatools', 2, 'sqatools', 3, 'sqatools', 4, 'sqatools']

Learn the concept

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

More tuple programs

← All 70 Tuple Programs

Leave a Comment