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

前端 未结 10 1654
太阳男子
太阳男子 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:29

    No

    According to the documentation, partial cannot do this (emphasis my own):

    partial.args

    The leftmost positional arguments that will be prepended to the positional arguments


    You could always just "fix" pow to have keyword args:

    _pow = pow
    pow = lambda x, y: _pow(x, y)
    

提交回复
热议问题