equivalent functions?

W

wietse

Hello,

I'm reading "Text processing in Python" by David Mertz. In there he
defines a function

apply_each = lambda fns, args=[]: map(apply, fns, [args]*len(fns))

I thought that this would be equivalent to:

apply_each = lambda fns, args=[]: [f(args) for f in fns]

Can anybody confirm this? If not, how are they different?
Thanks,
Wietse
 
L

Lonnie Princehouse

Very close... it is equivalent to:

apply_each = lambda fns, args=[]: [f(*args) for f in fns]

The asterisk in f(*args) expands the sequence to fill the arguments to
f, where as f(args) would pass the args as only the first argument to
the function.

apply is deprecated, replaced by the syntax: function( *args,
**keywords )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top