My aim is to create a function, list_powers, and use a for loop to take a list and return a new list (power_list) where each element is exponentiated to a specified power.
I have moved the return statement appropriately in order to collect all topowers in power_list and return them but it still returns None. How do I change it so that it returns the list of powers?
def list_powers(collection = [], power = 2):
power_list = []
for elem in collection:
topower = elem ** power
power_list.append(topower)
return power_list.append(topower)
test:
list_powers([2, 4, 1, 5, 12], power = 2)
output:
None