Open In App

Create a List of Tuples with Numbers and Their Cubes - Python

Last Updated : 25 Oct, 2025
Comments
Improve
Suggest changes
26 Likes
Like
Report

Given a list of numbers, the task is to create a list of tuples where each tuple contains a number and its cube. For example:

Input: [1, 2, 3]
Output: [(1, 1), (2, 8), (3, 27)]

Let’s explore different methods to achieve this efficiently in Python.

Using List Comprehension

This method uses list comprehension to generate the tuples directly while iterating over the list.

Python
a = [1, 2, 3, 4, 5]
res = [(n, n**3) for n in a]
print(res)

Output
[(1, 1), (2, 8), (3, 27), (4, 64), (5, 125)]

Explanation:

  • (n, n**3) for n in a iterates over each element n in the list and creates a tuple with the number and its cube.
  • Square brackets [ ] collect all tuples into a list.

Using map() with lambda

map() function applies a transformation function to each element of an iterable. It can be used with a lambda function to create the desired list of tuples.

Python
a = [1, 2, 3, 4, 5]
res = list(map(lambda n: (n, n**3), a))
print(res)

Output
[(1, 1), (2, 8), (3, 27), (4, 64), (5, 125)]

Explanation:

  • lambda n: (n, n**3) defines an anonymous function to create tuples of (number, cube).
  • map function applies the lambda to each element of numbers.
  • list() converts the result of map into a list.

Using zip()

This method separates numbers and their cubes into two lists and then combines them with zip().

Python
a = [1, 2, 3, 4, 5]
res = list(zip(a, [n**3 for n in a]))
print(res)

Output
[(1, 1), (2, 8), (3, 27), (4, 64), (5, 125)]

Explanation:

  • [n**3 for n in a] generates a list of cubes.
  • zip(a, cubes) pairs each number with its cube.
  • list() converts the pairs into a list of tuples.

Using for Loop with append()

This method uses a standard loop to build the list incrementally.

Python
a = [1, 2, 3, 4, 5]
res = []
for n in a:
    res.append((n, n**3))
print(res)

Output
[(1, 1), (2, 8), (3, 27), (4, 64), (5, 125)]

Explanation:

  • Initializes an empty list res.
  • Loops through each number and appends a tuple (n, n**3) to the list.

Explore