This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Marco Sulla
Recipients Marco Sulla
Date 2020-02-28.17:44:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1582911854.61.0.127481778131.issue39784@roundup.psfhosted.org>
In-reply-to
Content
I think a tuple comprehension could be very useful.

Currently, the only way to efficiently create a tuple from a comprehension is to create a list comprehension (generator comprehensions are more slow) and convert it with `tuple()`.

A tuple comprehension will do exactly the same thing, but without the creation of the intermediate list.

IMHO a tuple comprehension can be very useful, because:

1. there are many cases in which you create a list with a comprehension, but you'll never change it later. You could simply convert it with `tuple()`, but it will require more time
2. tuples uses less memory than lists
3. tuples can be interned

As syntax, I propose 

(* expr for x in iterable *)

with absolutely no blank character between the character ( and the *, and the same for ).

Well, I know, it's a bit strange syntax... but () are already taken by generator comprehensions. Furthermore, the * remembers a snowflake, and tuples are a sort of "frozenlists".
History
Date User Action Args
2020-02-28 17:44:14Marco Sullasetrecipients: + Marco Sulla
2020-02-28 17:44:14Marco Sullasetmessageid: <1582911854.61.0.127481778131.issue39784@roundup.psfhosted.org>
2020-02-28 17:44:14Marco Sullalinkissue39784 messages
2020-02-28 17:44:14Marco Sullacreate