List Comprehension Syntax

Peter Hansen peter at engcorp.com
Sun Jul 11 22:01:37 EDT 2004


Ville Vainio wrote:

> Nope, the only correct way is 
> 
> result = [x for x in range(10)
>           if x % 2 == 0
>           if x % 3 == 0
>           ]
> 
> result = [x * y
>           for x in range(10) if x % 2 == 0
>           for y in range(10) if y % 3 == 0
>           ]
> 
> Because that's the way python-mode.el does it in emacs :-).

Unfortunately, python-mode.el is wrong, since it results
in code that is harder to maintain (at least with another
editor).

Indentation that has to line up with random items on
the previous line, as opposed to the standard four spaces,
is clearly wrong.

But if you let emacs define the limits of your world, then
it's probably okay to do it that way.  ;-)



More information about the Python-list mailing list