[Python-Dev] map, filter, reduce, lambda
Andrew Koenig
ark@research.att.com
Thu, 30 Jan 2003 18:04:30 -0500 (EST)
Guido> I'll have to think about this more. lambda is annoying to me
Guido> because it adds so little compared to writing a one-line def.
Guido> But it makes sense for certain programming styles.
Yes -- there are times when notational compactness greatly aids mental
chunking. And of course there are other times when notational
compactness stands in the way of comprehension.
Sometimes a single notation can do both at once, depending on the
reader's prior experience. Consider the following C statement:
*p++ = *q++;
If you're an experienced programmer, the meaning of this statement
is immediately obvious; if not, it's obfuscation.
Similarly,
map(lambda x: x**2, data)
is really obvious to some people, and confusing to others, as is
[x**2 for x in data]
--
Andrew Koenig, ark@research.att.com, http://www.research.att.com/info/ark