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

S

Steven Bethard

Tom Anderson said:
> 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 said:
> 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 said:
> I'm not sure I find it truly hateful, but definitely unnecessary.
> TOOWTDI and all...

Paul said:
> 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
 
D

Diez B. Roggisch

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.

But you don't need the nested parentheses - use *args instead for the
list-constructor.

list(a,b,c)

Apart from that, I hope that the [] stay in. After all, if they are kept
around for literal list construction, the aren't free for other purposes
anyway.

Regards,

Diez
 
G

Giovanni Bajo

Diez said:
But you don't need the nested parentheses - use *args instead for the
list-constructor.

list(a,b,c)

No, you can't. That's ambigous if you pass only one argument, and that
argument is iterable. This is also the reason why set() doesn't work this
way.
 
S

Steve Holden

Diez said:
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.


But you don't need the nested parentheses - use *args instead for the
list-constructor.

list(a,b,c)

Apart from that, I hope that the [] stay in. After all, if they are kept
around for literal list construction, the aren't free for other purposes
anyway.
Traceback (most recent call last):

So you're talking about the way list() *should* work in Python 3, right?

regards
Steve
 
D

Diez B. Roggisch

Giovanni said:
No, you can't. That's ambigous if you pass only one argument, and that
argument is iterable. This is also the reason why set() doesn't work this
way.

Ah, you're right - I thought about the >1 case, but not that one.

Regards,

Diez
 
D

Diez B. Roggisch

Steve said:
Diez said:
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.


But you don't need the nested parentheses - use *args instead for the
list-constructor.

list(a,b,c)

Apart from that, I hope that the [] stay in. After all, if they are
kept around for literal list construction, the aren't free for other
purposes anyway.
list(1,2,3)
Traceback (most recent call last):

So you're talking about the way list() *should* work in Python 3, right?

Yes, should have said "could" there. But as Giovanni pointed out I
missed the ambiguity in case of the size one lists.

Diez
 
A

Antoon Pardon

Op 2006-01-18 said:
Ah, you're right - I thought about the >1 case, but not that one.

Well we could have list(a) return [a], and have a list_from_iterable.
Although I would prefer a different name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top