List comprehension confusion...
Peter Hansen
peter at engcorp.com
Sun Feb 2 05:04:34 EST 2003
Lulu of the Lotus-Eaters wrote:
>
> Peter Hansen <peter at engcorp.com> wrote previously:
> |> result = map(lambda t: t.some_field, data)
> |I find map very readable as well... but not lambdas. :-)
>
> I actually kinda agree. Most people dread lambdas because of what they
> are (the semantics). Myself, I only have trouble with their spelling.
Yeah, it's basically the syntax. I find the missing return statement
bothersome, somewhere in the back of my mind, and also the parentheses
that aren't there around the arguments... When I mentally shift the
image to imagine them there, I can get the syntax right, but it always
takes a moment of hesitation.
At first I had trouble with list comprehensions, too. Would have
help to actually read what they were, I suppose, instead of just
looking at code trying to understand what they did. Some kind soul's
post in this newsgroup simplified the concept enough that my brain
got over the hump and now they're definitely more straightforward
for me than most map/lambda combos.
-Peter
More information about the Python-list
mailing list