expression form of one-to-many dict?

Fernando Perez fperez528 at yahoo.com
Fri Dec 17 19:22:53 EST 2004


Steven Bethard wrote:

> Actually, it's even smaller now, because I've pretty much removed map
> from all my code in favor of list comprehensions, which I find much
> easier to read.

While I agree that listcomps are more readable in most cases (and certainly for
all cases with any amount of complexity in the listcomp), I still find that
map is hard to beat for the simple case of a callable foo:

outlist = map(foo,inlist)

is still better in my book, and far more readable, than

outlist = [foo(x) for x in inlist]

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 :)

Since I tend to have a lot of code like this, I really cringe when I hear of a
desire to do away with map altogether.  I know I could rewrite it myself in
all my code, but the beauty of these builtins is that they are always there...

Cheers,

f




More information about the Python-list mailing list