On 11/17/19 9:39 PM, Daniel Zeng wrote:
Syntax for tuple comprehension, something like:
(i, for i in range(10))
This shouldn't result in ambiguity, since generators need to be in
parentheses anyway:
(i, for i in range(10)) vs (1, (i for i in range(10)))
The existing comprehensions support the extensible collections (list,
dict, set, generator). These are things with arbitrary, flexible, and
often (at coding time) unknown lengths. Tuples are not like that: they
are meant more for collections where the length is known at coding time
because the positions of the elements have meaning: (name, address,
phonenumber), or (host, port), etc. This is not an absolute rule, but
is a very common distinction between lists and tuples.
There are uses for comprehension syntax for making tuples, but they
occur far far less frequently than the comprehensions we have. To me,
the existing way to do it makes perfect sense, and exactly expresses
what needs to happen:
tuple(i for i in range(10))
(ignoring the two or three ways that this is an unrealistic toy example).
There's no need to invent a tortured and confusing syntax to support
making tuples with comprehensions. We already have a fine way to do it.
--Ned.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/FPZ6OMNOLLCZHA7EJUV5DEGDO5DQNRIM/
Code of Conduct: http://python.org/psf/codeofconduct/