Arguments for map'ped functions

mk mrkafk at gmail.com
Thu Feb 5 07:54:15 EST 2009


Hello everyone,

So I have this function I want to map onto a list of sequences of 
*several* arguments (while I would want to pass those arguments to each 
function in the normal fashion). I realize this is contrived, maybe an 
example would make this clear:

params = [ ('comp.lang.python', ['rtfm', 'shut']), ('comp.lang.perl', 
['rtfm','shut']) ]

qurls = map(consqurls, params)

def consqurls(args):
     ggroup, gkeywords = args
...

Since the argument passed to map'ped function is a single tuple of 
arguments, I have to unpack them in the function. So the question is how 
to pass several arguments to a map'ped function here?


Code in question:

def fillurlfmt(args):
     urlfmt, ggroup, gkw = args
     return {'group':ggroup, 'keyword':gkw, 'url': urlfmt % (gkw, ggroup)}

def consqurls(args):
     ggroup, gkeywords = args
     urlfmt = 
'http://groups.google.com/groups/search?as_q=%s&as_epq=&as_oq=&as_eq=&num=10&scoring=&lr=&as_sitesearch=&as_qdr=&as_drrb=b&as_mind=1&as_minm=1&as_miny=1999&as_maxd=1&as_maxm=1&as_maxy=2009&as_ugroup=%s&as_usubject=&as_uauthors=&safe=off'
     qurls = map(fillurlfmt, [ (urlfmt, ggroup, gkw) for gkw in gkeywords])
     return qurls

if __name__ == "__main__":
     gkeywords = ['rtfm', 'shut']
     ggroups = ['comp.lang.python', 'comp.lang.perl']
     params = [(ggroup, gkeywords) for ggroup in ggroups]
     qurls = map(consqurls, params)
     print qurls

Regards,
mk




More information about the Python-list mailing list