[Tutor] a quetion on"There should be one and preferabley one obvious way to do it"
Michael P. Reilly
arcege@speakeasy.net
Tue, 22 Jan 2002 15:05:33 -0500
On Tue, Jan 22, 2002 at 12:00:00AM -0000, alan.gauld@bt.com wrote:
> > List comprehensions replace a lot of map(lambda...)
> > garbage which is very unsightly.
>
> I disagree. I find the map(lambda... ) form much more
> readable than the confusion that is comprehensions.
> Every time I see a comprehension I have to mentally
> rewrite it in a for loop form.
>
> But then I spent a lot of time reading Lisp where every
> function starts like:
>
> (define foo
> (lambda x ....))
>
> Which is directly equivalet to:
>
> foo = lambda x:....
>
> in Python.
>
> To me a map looks much cleaner than a comprehension!
> (But is less flexible I think)
>
> Alan G
> (Who is almost certainly in a minority of one on this! :-)
I quite agree, Alan. I think list comprehensions make for a more
confusing form. But then maybe it is because my favorite language used
to be Lisp, where apply, map, etc. were common and elegant.
Syntactically and semantically in Python, something is confusing between
having "for var in seq" as both a statement AND and expression - and
that really smells of Perl (which wasn't a pleasant thought to me).
Map, filter, reduce, they all have the same simple, predictable form.
But list comprehensions have a far more complicated form might want to
use it.
List comprehensions may make the code look cleaner, but I do not think
that they make the algorithm much clearer for the most part.
-Arcege