python - Using map() function with keyword arguments -


here loop trying use map function on:

volume_ids = [1,2,3,4,5] ip = '172.12.13.122' volume_id in volume_ids:     my_function(volume_id, ip=ip) 

is there way can this? trivial if weren't ip parameter, i'm not sure how deal that.

use functools.partial():

from functools import partial  mapfunc = partial(my_function, ip=ip) map(mapfunc, volume_ids) 

partial() creates new callable, that'll apply arguments (including keyword arguments) wrapped function in addition whatever being passed new callable.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -