Program to create the tuple with elements as number and its cube from the given list of tuple using Python

Introduction

The task is to create a tuple from the given tuple with the first elements as the number and second element as its cube values.

Program to create the tuple with elements as number and its cube from the given list of tuple using Python 

 

Program

input_list = [1, 2, 5, 6]

print("The given tuple is: ", input_list)

# Using list comprehension

output = [ (val, pow(val, 3)) for val in input_list]




print("The output tuple is :", output)

Output

Program to create the tuple with elements as number and its cube from the given list of tuple Output

Explanation

To achieve our task we have used list comprehension approach. Using list comprehension, we have iterated through each value in the given list of tuple and the result is stored in output variable as element and element cube.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.