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 | Remove tuple from list of tuples if not containing any character
- Python | Group by matching second tuple value in list of tuples
- Python | Pair and combine nested list to tuple list
- Python | Convert list of tuples to list of list
- 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 strings
- Python | Remove tuples having duplicate first value from given list of tuples
- Python | Remove tuples from list of tuples if greater than n
- Python | Find the tuples containing the given element from a list of tuples
- Python | Count tuples occurrence in list of tuples
- Python | Update a list of tuples using another list
- Python | Convert list of tuples into list
- Python | Convert a list into a tuple
- Python | Convert a list into tuple of lists
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.