Given a list of numbers of list, write a Python program to create a list of tuples having first element as the number and second element as the cube of the number.
Input: list = [1, 2, 3] Output: [(1, 1), (2, 8), (3, 27)] Input: list = [9, 5, 6] Output: [(9, 729), (5, 125), (6, 216)]
We can use list comprehension to create a list of tuples. The first element will be simply an element and second element will be cube of that number.
Below is the Python implementation:
[(1, 1), (2, 8), (5, 125), (6, 216)]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course