When it is required to compute the power by index element in a list, the simple iteration along with the ‘**’ operator is used.
Example
Below is a demonstration of the same
my_list = [62, 18, 12, 63, 44, 75] print("The list is :") print(my_list) my_result = [] for my_index, elem in enumerate(my_list): my_result.append(elem ** my_index) print("The result is :") print(my_result)
Output
The list is : [62, 18, 12, 63, 44, 75] The result is : [1, 18, 144, 250047, 3748096, 2373046875]
Explanation
A list is defined and is displayed on the console.
An empty list is defined.
The list is iterated over and the element raised to the power of the index is appended to the empty list.
This is displayed as output on the console.