map, filter & reduce...
Ben
crescent_au at yahoo.com
Sun Nov 16 07:16:44 EST 2003
Hi all,
I'm trying to figure out how how complex map, filter and reduce work
based on the following piece of code from
http://www-106.ibm.com/developerworks/linux/library/l-prog.html :
bigmuls = lambda xs,ys: filter(lambda (x,y):x*y > 25, combine(xs,ys))
combine = lambda xs,ys: map(None, xs*len(ys), dupelms(ys,len(xs)))
dupelms = lambda lst,n: reduce(lambda s,t:s+t, map(lambda l,n=n:
[l]*n, lst))
print bigmuls((1,2,3,4),(10,15,3,22))
The solution generated by the above code is: [(3, 10), (4, 10), (2,
15), (3, 15), (4, 15), (2, 22), (3, 22), (4, 22)]
I'm stuck on the second line in "map(None, xs*len(ys),
dupelms(ys,len(xs))"... Can someone explain me how the map function
evaluates??
Thanks
Ben
More information about the Python-list
mailing list