
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Create a list of tuples from given list having number and its cube in each tuple using Python
When it is required to create a list from a given list that have a number and its cube, the list comprehension can be used.
Below is the demonstration of the same −
Example
my_list = [32, 54, 47, 89] print("The list is ") print(my_list) my_result = [(val, pow(val, 3)) for val in my_list] print("The result is ") print(my_result)
Output
The list is [32, 54, 47, 89] The result is [(32, 32768), (54, 157464), (47, 103823), (89, 704969)]
Explanation
A list is defined, and is displayed on the console.
The list comprehension is used to iterate through the list, and use the ‘pow’ method to get the cube of the integer.
This is assigned to a result.
This result is displayed as output on the console.
- Related Articles
- Python program to create a list of tuples from the given list having the number and its cube in each tuple
- Remove tuples having duplicate first value from given list of tuples in Python
- Reverse each tuple in a list of tuples in Python
- Create a tuple from string and list in Python
- Python – Remove Tuples from a List having every element as None
- Sort a List of Tuples in Increasing Order by the Last Element in Each Tuple using Python program
- Find the tuples containing the given element from a list of tuples in Python
- Update a list of tuples using another list in Python
- Combinations of sum with tuples in tuple list in Python
- Remove tuple from list of tuples if not containing any character in Python
- Remove duplicate tuples from list of tuples in Python
- Python – Filter all uppercase characters from given list of tuples
- Remove Tuples from the List having every element as None in Python
- How to create a tuple from a string and a list of strings in Python?
- Python Group by matching second tuple value in list of tuples

Advertisements