Table of Contents
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
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
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.
0 Comments