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 | Reverse each tuple in a list of tuples
- Python | Swap tuple elements in 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 program to sort a list of tuples by second Item
- Python | Program to count duplicates in a list of tuples
- 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 | Merge list of tuple into list by joining the strings
- Python | Pair and combine nested list to tuple list
- Python | Remove duplicate tuples from list of tuples
- Python | Find the tuples containing the given element from a list of tuples
- Python | Remove tuples from list of tuples if greater than n
- Python | Remove tuples having duplicate first value from given list of 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.