Python Practice › Tuple Programs › Program 15
Tuple of squares from a list
Write a Python program to create a tuple of the squares of a list’s elements.
Input
[1, 9, 5, 7, 6]
Output
(1, 81, 25, 49, 36)
Approach
- Pass a generator expression to
tuple().
Solution
print(tuple(n * n for n in [1, 9, 5, 7, 6]))Output
(1, 81, 25, 49, 36)
Learn the concept
New to this topic? Read the lesson, then come back.