Jacek:
Given a population with previous exposure to computer programming, my
money is on the map-lambda version. But this last point is mostly
irrelevant. The fact is that you cannot program computers without
doing a bit of learning ... and the lambda, map and friends really do
not take any significant learning.
This kind of "sociological" study would be pretty interesting to me ;-)
Personally, I find out that my mind manage pretty well one-level of
indirection
at time, not two. Consider for instance
def add1(x): return x+1
map(add1, mylist)
Here there are *two* levels of indirection:
first, I need to define add1;
second I need to translate mentally map to a loop.
Using lambda does not help:
map(lambda x: x+1, mylist)
still would require two levels for me, one to recognize the lambda
and one to convert map to a loop.
This is too much for me, so I just write
[x+1 for x in mylist]
where everything is explicit (or if you wish, I have just to recognize
that there
is a loop going on, pretty easy).
However, if I can skip a level of indirection (i.e. I do not need to
define
a function) I just prefer map:
map(int, mylist)
is simpler for me than
[int(x) for x in mylist]
since the latter introduces an useless x (which is also polluting my
namespace,
but this not my point, I could use a generator-expression instead).
So, in practice, I only use map with built-in or with predefined
functions, i.e. functions
which are already there for some other purpose; I do not like to be
forced to write a
function (or a lambda) for the only purpose of using map (at least in
Python).
Incidentally, I am not fond of the name "lambda" too. "fn", as Paul
Graham says,
looks much better.
What I would like, in Python, is some facility to manage callbacks in
the standard
library, then I would live pretty well without lambdas.
Just IMHO, YMMV, etc.
Michele Simionato