On Sat, Oct 16, 2021, 12:08 PM Steven D'Aprano
unpacking in *comprehensions*.
# not currently permitted
[*s for s in ["abc", "def", "ghi"]]
> Moreover, it is an anti-pattern to create large and indefinite sized tuples,
Is it? In what way?
As mentioned, I clipped the wrong part.
That said, even `(*it1, *it2, *it3)` feels like an anti-pattern in most cases, although syntactically defined. A hypothetical "tuple comprehension" seems that much worse.
I'm not making any claims about tuple creation speed vs. list creation on microbenchmarks. It might we'll be 10% faster to create a million item tuple than a million item list. Or maybe the opposite, I don't know.
Rather, I'm concerned with readability and programmer expectations. Tuples are best used as "records" of heterogeneous but structured data. This is what makes namedtuples such an elegant extension. When I see a collection of tuples, I generally expect each to have the same "shape", such as a string at index 0, a float at index 1, and an int at index 2. If those positions have attribute names, so much the better.
In contrast, lists (and iterators) I expect to contain many things that are "the same" in a duck-type way. I usually want to loop through them and perform the same operation on each (maybe with some switches, but in the same block).
Having a million such similar items is commonplace. Having a million *fields* is non-existent.