?

Log in

No account? Create an account

Previous Entry | Next Entry

Continuing Education

Yesterday I was reading about text processing in python, excitement for all. When I ran across a discussion of higher order functions, one in particular was the following.
apply_each = lambda fns, args=[]: map(apply, fns, [args]*len(fns))

What this did was not obvious to me, since I didn't know about map, apply, and multiplying a list by a cardinal. After some study, and playing around in the python interpreter I learned It has the following affect. Invoke each function in fns and use the arguments in the list args, and return a list with the result of each function. It turns out that 'apply' has been deprecated in python. In favor of the function(*args, **kw) syntax. What this essentially means is that apply_each should now be written as follows:
def apply_each(fns, *args, **kw):
    return [f(*args, **kw) for f in fns]


Thanks to veloso for helping me with the *,** syntax.

Latest Month

July 2011
S M T W T F S
     12
3456789
10111213141516
17181920212223
24252627282930
31      
Powered by LiveJournal.com
Designed by yoksel