Can one partially apply the second argument of a function that takes no keyword arguments?

前端 未结 10 1680
太阳男子
太阳男子 2020-11-28 06:45

Take for example the python built in pow() function.

xs = [1,2,3,4,5,6,7,8]

from functools import partial

list(map(partial(pow,2),xs))

>&g         


        
10条回答
  •  半阙折子戏
    2020-11-28 07:37

    Why not just create a quick lambda function which reorders the args and partial that

    partial(lambda p, x: pow(x, p), 2)
    

提交回复
热议问题