On Sat, 16 Oct 2021, David Mertz, Ph.D. wrote:

On Sat, Oct 16, 2021, 10:10 AM Erik Demaine
      (*it1, *it2, *it3)  # tuple with the concatenation of three
      iterables
      [*it1, *it2, *it3]  # list with the concatenation of three
      iterables
      {*it1, *it2, *it3}  # set with the union of three iterables
      {**dict1, **dict2, **dict3}  # dict with the combination of
three dicts I'm +0 on the last three of these.
But the first one is much more suggestive of a generator comprehension. I
would want/expect it to be equivalent to itertools.chain(), not create a
tuple.

I guess you were referring to `(*it for it in its)` (proposed notation) rather than `(*it1, *it2, *it3)` (which already exists and builds a tuple).

Very good point! This is confusing. I could also read `(*it for it in its)` as wanting to build the following generator (or something like it):

```
def generate():
    for it in its:
        yield from it
```

I guess the question is whether to define `(*it for it in its)` to mean tuple or generator comprehension or nothing at all. Tuples are nice because they mirror `(*it1, *it2, *it3)` but bad for the reasons you raise:

Moreover, it is an anti-pattern to create large and indefinite sized tuples,
whereas such large collections as lists, sets, and dicts are common and
useful.

I'd be inclined to not define `(*it for it in its)`, given the ambiguity.

Assuming the support remains relatively unanimous for [*...], {*...}, and {**...} (thanks for all the quick replies!), I'll put together a PEP.

On Sat, 16 Oct 2021, Guido van Rossum wrote:

Seems sensible to me. I’d write the equivalency as

for x in y: answer.extend([…x…])

Oh, nice!  That indeed works in all cases.

Erik
--
Erik Demaine  |  edema...@mit.edu  |  http://erikdemaine.org/
_______________________________________________
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/2AZBMZGKL56PERIJRCPTIJ6BRITTWHGM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to