M
mk
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/sea..._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
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/sea..._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