Securing a future for anonymous functions in Python
jacek.generowicz at cern.ch
Tue Jan 11 09:34:50 CET 2005
Jeff Shannon <jeff at ccvcorp.com> writes:
> Jacek Generowicz wrote:
> > "Anna" <annaraven at gmail.com> writes:
> >>But first, wouldn't something like:
> >>[x+1 for x in seq]
> >>be even clearer?
> > I'm glad you mentioned that. [...]
> > As to whether it is clearer. That depends. I would venture to suggest
> > that, given a pool of laboratory rats with no previous exposure to
> > Python, more of them would understand the map-lambda than the list
> > comprehension.
> I would venture to suggest the exact opposite, that the syntax of a
> list comprehension is in itself suggestive of its meaning, while 'map'
> and 'lambda' are opaque until you've researched them.
In the population of all laboratory rats, I think that the proportion
that would understand either form, would be as good as zero.
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.
> Speaking for *this* laboratory rat, at least, map/lambda was always a
> nasty puzzle for me and difficult to sort out. But when list comps
> were introduced, after reading just a sentence or two on how they
> worked, they were completely clear and understandable -- much more so
> than map/lambda after many months of exposure.
Forgetting about lambda, map, filter and reduce, do you find that you
pass callables around in your Python programs, or is this not
typically done in your programs?
More information about the Python-list