How can I raise the numbers in list to a certain power?
You can simply do:
numbers=[1,2,3,4,5,6,7,8,9]
numbers3 = []
for n in numbers:
numbers3.append(n**3)
print('Original list:', numbers)
print('Cubic list:', numbers3)
Another map
pattern, using lambda
instead of function.partial()
:
numbers=[1,2,3,4]
squares=list(map(lambda x:pow(x,2),numbers))
print(squares)