Array comprehension syntax

Claus Reinke claus.reinke at talk21.com
Mon Sep 24 08:09:33 PDT 2012


0. yes to (for|if)* - also for generator expressions

1. Array comprehensions with for/if do not look very readable - 
    the generators and filters seem to merge into one blob of text. 

>>> [x*y for x of range(XDIM) if x&1 for y of range(YDIM)]

    While syntax highlighting and/or formatting can help
    to make the individual items stand out:

    [x*y for x of range(XDIM)
            if x&1
            for y of range(YDIM)]

    There may be syntactic alternatives that make it easier to
    spot and separate the generators and filters. ES syntax
    tweaking is notoriously tricky, but perhaps something like

    [ x*y : x of range(XDIM); x&1; y of range(YDIM) ]   

Claus
 


More information about the es-discuss mailing list