expression form of one-to-many dict?

Terry Reedy tjreedy at udel.edu
Sat Dec 18 15:35:56 EST 2004


In respect to map(func, seq) versus [func(i) for i in seq], for 
pre-existing func, 'OP' wrote

>>>>The map form, in this case, parses instantly in my brain, while the 
>>>>listcomp
>>>>certainly takes a few cycles.  And note that I'm not talking about the 
>>>>typing
>>>>conciseness, but about the effort for my brain.  But maybe I'm just 
>>>>wired
>>>>funny :)

>> Steven Bethard wrote:
>>>Well, different at least.  I find the map one harder to parse mentally.
[and]
> [1] In my mind, the program flow is spelled out explicitly in the list 
> comprehension and only implicitly in the map application.  Thus the list 
> comprehension is clearer to me.

For pre-existing func, I slightly prefer the map form because the 
sequential program flow is *not* spelled out.  So I can more easily see the 
sequence items mapped in parallel.  On the other hand, I probably prefer 
[i-expression for i in seq] to map(lambda i: i-expression, seq) because I 
find the (unnecessary) mental construction of a function object to be a 
compensating burden.

I can easily imagine that others will find themselves more comfortably on 
one side or the other of the mental fence I find myself sitting on ;-).

Terry J. Reedy 






More information about the Python-list mailing list