Python Practice › Tuple Programs › Program 54
Flatten tuples into a string
Write a Python program to flatten a list of tuples into a space-separated string.
Input
[("s", "q", "a"), ("t", "o"), ("o", "l", "s")]Output
s q a t o o l s
Approach
- Join every item with spaces.
Solution
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
Learn the concept
New to this topic? Read the lesson, then come back.