Reverse of map()?

Raymond Hettinger python at rcn.com
Sun Feb 5 23:46:06 EST 2006


[Alex Martelli]
> map(apply, fn_list, ...) may work, but I doubt it's going to be either
> simple or speedy since the ... must be replaced with as many copies of
> Args and Kwds as there are functions in fn_list, e.g.:
>
> map(apply, fn_list, len(fn_list)*(Args,), len(fn_list)*(Kwds))

The repeat() function in the itertools module was designed to fulfill
this need and consume less memory in the process:

    from itertools import repeat
    n = len(fn_list)
    map(apply, fn_list, repeat(Args, n), repeat(Kwds, n))



> There's no built-in that calls many functions with identical args and
> kwds, since it's a rare need.

Also, it is almost certain that the function calls and their execution
will dominate his runtime.  Even if the fantasied rmap() function
existed, it would be unlikely to help.


Raymond




More information about the Python-list mailing list