[Tutor] Tutor Digest, Vol 15, Issue 40

Kent Johnson kent37 at tds.net
Wed May 18 05:01:39 CEST 2005


jfouhy at paradise.net.nz wrote:
> Quoting Kent Johnson <kent37 at tds.net>:
> 
> 
>>J. Gabriel Schenz wrote:
>>
>>>Now, I am new to Python as well, but it seems like apply might not be
>>>completely superfluous. I was thinking that if one were using a functional
>>>programming style, and had to apply a function determined at runtime to an
>>>argument, then one could use this apply to do so. 
>>
>>apply() is superfluous. apply(function, args[, keywords]) is exactly
>>equivalent to function(*args, [**keywords]). 
> 
> 
> Ooh.  Functional programming is fun!
> 
> 
>>>>multers = [i.__mul__ for i in range(10)]
>>>>mulTable = [[f(i) for i in range(10)] for f in multers]

or use mulTable = [[i*j for i in range(10)] for j in range(10)] if you prefer conciseness and 
readability :-)

Kent



More information about the Tutor mailing list