Python Practice › Tuple Programs › Program 15

Tuple of squares from a list

EasyTuple Programs · 15 of 70

Write a Python program to create a tuple of the squares of a list’s elements.

Advertisement
Input
[1, 9, 5, 7, 6]
Output
(1, 81, 25, 49, 36)

Approach

  1. Pass a generator expression to tuple().

Solution

Python
print(tuple(n * n for n in [1, 9, 5, 7, 6]))
Output
(1, 81, 25, 49, 36)
Advertisement

Learn the concept

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

More tuple programs

← All 70 Tuple Programs