Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Transform tuple elements using map

Apply a function to every element of a tuple using map and return a new tuple.

Python practice10 minFunctions as Objects (Lambda, Map/Filter)BeginnerLast updated March 20, 2026

Problem statement

Write a function transform_tuple(tpl, func) that takes a tuple tpl and a single-argument function func, applies func to each element of tpl using map, and returns a new tuple with the transformed values. The function should work for any callable func passed in (including lambdas).

Task

Practice using map to transform elements and convert the result back to a tuple.

Examples

Double integers

Input

(1, 2, 3), lambda x: x*2

Output

(2, 4, 6)

Each value is doubled via the provided lambda.

Input format

Two arguments: a tuple and a function (callable) to apply to each element.

Output format

A tuple containing the transformed elements.

Constraints

Use map(...) to apply the function. Do not use list/dict comprehensions to replace map entirely.

Samples

Sample 1

Input

('a', 'b'), lambda s: s.upper()

Output

('A', 'B')

The lambda converts each string to uppercase.