Python Practice › Tuple Programs › Program 54

Flatten tuples into a string

EasyTuple Programs · 54 of 70

Write a Python program to flatten a list of tuples into a space-separated string.

Advertisement
Input
[("s", "q", "a"), ("t", "o"), ("o", "l", "s")]
Output
s q a t o o l s

Approach

  1. Join every item with spaces.

Solution

Python
data = [("s", "q", "a"), ("t", "o"), ("o", "l", "s")]print(" ".join(x for t in data for x in t))
Output
s q a t o o l s
Advertisement

Learn the concept

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

More tuple programs

← All 70 Tuple Programs