Raising elements of a list to a power

前端 未结 8 1943
傲寒
傲寒 2020-12-17 18:02

How can I raise the numbers in list to a certain power?

8条回答
  •  庸人自扰
    2020-12-17 18:48

    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)
    

提交回复
热议问题