list(...) and list comprehensions (WAS: Arithmetic sequences in Python)

Steven Bethard steven.bethard at gmail.com
Wed Jan 18 13:24:58 EST 2006


Tom Anderson <twic at urchin.earth.li> wrote:
 > Sounds good. More generally, i'd be more than happy to get rid of list
 > comprehensions, letting people use list(genexp) instead. That would
 > obviously be a Py3k thing, though.

Alex Martelli wrote:
 > I fully agree, but the BDFL has already (tentatively, I hope)
 > Pronounced that the [...] form will stay in Py3K as syntax sugar for
 > list(...). I find that to be a truly hateful prospect, but that's the
 > prospect:-(.

Steven Bethard wrote:
 > I'm not sure I find it truly hateful, but definitely unnecessary.
 > TOOWTDI and all...

Paul Rubin wrote:
 > Well, [...] notation for regular lists (as opposed to list
 > comprehensions) is also unnecessary since we could use
 > "list((a,b,c))".

I'm not sure that's really a fair comparison.  Do you really find:

     list(x**2 for x in iterable)

harder to read than:

     [x**2 for x in iterable]

??  I don't, though perhaps this is just me.  OTOH, I do find:

     list((a, b, c))

to be substantially harder to read than:

     [a, b, c]

due to the nested parentheses.  Note that replacing list comprehensions 
with list(...) doesn't introduce any nested parentheses; it basically 
just replaces brackets with parentheses.

Just in case there was any confusion, I definitely wasn't suggesting 
that we remove list literal support.

STeVe



More information about the Python-list mailing list