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)]
- Python - Combinations of sum with tuples in tuple list
- Python | Reverse each tuple in a list of tuples
- Python | Group by matching second tuple value in list of tuples
- Python | Remove tuple from list of tuples if not containing any character
- Python | Swap tuple elements in list of tuples
- Create a tuple from string and list - Python
- Python | Program to count duplicates in a list of tuples
- Python program to sort a list of tuples alphabetically
- Python program to sort a list of tuples by second Item
- Python | Convert list of tuples to list of list
- Python | Convert list of strings to list of tuples
- Python | Convert list of tuples to list of strings
- Python | Convert mixed data types tuple list to string list
- Python | Remove duplicate tuples from list of tuples
- Python | Convert string tuples to list tuples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.