How to cube each element in a list with Python

2 Answers

0 votes
import numpy as np

lst = range(7)
print(*lst)

lst = np.float_power(lst, 3)
print(lst)



'''
run:

0 1 2 3 4 5 6
[  0.   1.   8.  27.  64. 125. 216.]

'''

 



answered Jun 17, 2023 by avibootz
0 votes
import numpy as np

lst = range(7)
print(*lst)

lst = np.power(lst, 3)
print(lst)



'''
run:

0 1 2 3 4 5 6
[  0   1   8  27  64 125 216]

'''

 



answered Jun 17, 2023 by avibootz
...