- Trending Categories
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 – Find Product of Index Value and find the Summation
When it is required to find the product of the index value and the summation, the ‘enumerate’ attribute is used.
Example
Below is a demonstration of the same
my_list = [71, 23, 53, 94, 85, 26, 0, 8] print("The list is :") print(my_list) my_result = 0 for index, element in enumerate(my_list): my_result += (index + 1) * element print("The resultant sum is :") print(my_result)
Output
The list is : [71, 23, 53, 94, 85, 26, 0, 8] The resultant sum is : 1297
Explanation
A list of integers is defined and is displayed on the console.
An integer value is assigned to 0.
The enumerate value is used to iterate through the list.
The index is multipled with the respective element and this is added to the integer value.
This is the output that is displayed on the console.
Advertisements