def indexed_partial(func, list_of_index, *args):

    def partially_applied_function(*fargs, **fkwargs):
        nargs = len(args) + len(fargs)
iargs = iter(args)
ifargs = iter(fargs)
posargs = (next((ifargs, iargs)[i in list_of_index]) for i in range(nargs))
return func(*posargs, **fkwargs)
return partially_applied_function
how to partially apply arbitrary argument of a function?