On Thu, Jun 17, 2021 at 3:09 PM Steven D'Aprano <st...@pearwood.info> wrote:

> On Thu, Jun 17, 2021 at 02:22:29PM -0700, Ben Rudiak-Gould wrote:
> >     [*chunk for chunk in list_of_lists]
>
> What would that do?


The difference between chunk and *chunk in the expression of a list
comprehension would be the same as the difference between them in the
expressions of a starred_list.

The only thing I can guess it would do is the
> equivalent of:
>
>     result = []
>     for chunk in list_of_lists:
>         result.append(*chunk)
>
> which is a long and obfuscated way of saying `raise TypeError` :-)
>

It would be reasonable to allow list.append to take any number of arguments
to be appended to the list, as though its definition was

    def append(self, *args):
        self.extend(args)

If it did, then that translation would work and do the right thing.

Some similar functions do accept multiple arguments as a convenience,
though it's not very consistent:

    myset.add(1, 2)  # no
    myset.update([1, 2], [3, 4])  # ok
    mylist.append(1, 2)  # no
    mylist.extend([1, 2], [3, 4])  # no
    mydict.update({'a': 1}, b=2, c=3)  # ok
    mydict.update({'a': 1}, {'b': 2}, c=3)  # no

Well, there is this:
>
>     result = []
>     for chunk in list_of_lists:
>         *temp, = chunk
>         result.append(temp)
>
> which would make it an obfuscated way to spell `list(chunk)`.
>

Unpacking would be useless in every context if you interpreted it like that.
_______________________________________________
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/NNZKPJUD73WIQPUHZ3QNWPHQSM6BYUDP/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to