- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to find the cube of each list element
When it is required to find the cube of each list element, a simple iteration and the ‘append’ method are used.
Example
Below is a demonstration of the same
my_list = [45, 31, 22, 48, 59, 99, 0] print("The list is :") print(my_list) my_result = [] for i in my_list: my_result.append(i*i*i) print("The resultant list is :") print(my_result)
Output
The list is : [45, 31, 22, 48, 59, 99, 0] The resultant list is : [91125, 29791, 10648, 110592, 205379, 970299, 0]
Explanation
A list is defined and is displayed on the console.
An empty list is defined.
The original list is iterated over.
Every element is multiplied with itself thrice.
This result is appended to the empty list.
This is the result that is displayed on the console.
Advertisements