[Tutor] apply() vs. the extended call syntax
Albert-Jan Roskam
fomcl at yahoo.com
Sat Aug 3 11:02:36 CEST 2013
----- Original Message -----
> From: Peter Otten <__peter__ at web.de>
> To: tutor at python.org
> Cc:
> Sent: Saturday, August 3, 2013 8:32 AM
> Subject: Re: [Tutor] apply() vs. the extended call syntax
>
>T im Johnson wrote:
>
>> Frequently I use a function dispatch approach like this:
>> funcs = {"key1":func1,"key2":func2}
>>
>> ## and call one of those functions with a key value
>> ## as follows
>> funcs[key](some,fixed,number,of,arguments)
>>
>> Less frequently, I might want to dispatch functions with variable
>> numbers of arguments.
>>
>> Follows is an illustrative (hopefully) REPL session
>> ## define a couple of simple function
>> def test_apply(one,two): print(str(one) + " " + str(two))
>> def func_two(): print("I don't have an argument!")
>>
>> ## define references to one or more functions and argument lists
>> ## of variable lengths
>>
>> func_D =
> {"key1":(test_apply,("one","two")),
> "key2":(func_two,())}
>>
>> ## give a key some value
>> k = "key1"
>>
>> ## Use the deprecated apply() function first
Is there a reason why the apply function is deprecated/gone, but map() isn't? Aren't they both based on the lisp-style functional programming approach?
More information about the Tutor
mailing list