List Comprehension Syntax

Peter Hansen peter at engcorp.com
Mon Jul 12 13:18:18 EDT 2004


Isaac To wrote:

> Except that if you write things like
> 
> a=[[[1, 2],
>     [3, 4],
>     [5, 6]],
>    [[7, 8],
>     [5, 6]],
>    [9]]
> 
> as
> 
> a=[[[1, 2],
>         [3, 4],
>         [5, 6]],
>     [[7, 8],
>         [5, 6]],
>     [9]]
> 
> and say there is no lose of legibility, then I'll seriously question
> your taste.

Ugh.  But nobody should write something like the first one, either.
(And I won't say how it should be written without a real example,
since otherwise we can each contrive all kinds of interesting and
meaningless ways to format something that nobody would actually
write.)

> BTW, for somebody with python-mode installed and is using Emacs, it is
> actually *harder* and a *bigger* waste of time to write the code as
> you proposed, because by default whenever you press enter the cursor
> is already at exactly the location in the former style, and you got to
> count spaces in order to go to the place you proposed.

Not sure which one you think I proposed, but you definitely don't
have to count any spaces in order to do what I suggested.  You
hit ENTER and TAB (once), exactly as you would with any other
block.  Note that this (hitting TAB once) of course relies on
an editor which auto-indents to the same level as the preceding
line of code by default.  Any editor which does not do at least
this, these days, is broken.  But counting spaces would be silly.
What editor are you using that would force you to do that?  vi
without a Python configuration?

-Peter



More information about the Python-list mailing list