>>> LOL = [[1, 2], ['three']]
>>> [*LOL[0], *LOL[1]]
[1, 2, 'three']
Alright! Goodbye itertools.chain
. Never liked you much anyway.
>>> [*L for L in LOL]
File "<ipython-input-21-e86d2c09c33f>", line 1
[*L for L in LOL]
^
SyntaxError: iterable unpacking cannot be used in comprehension
Oh. Why can't we have nice things?
Unpacking in a comprehension seems to be obvious/pythonic, but since they've bothered to add that special error message there was a reason for disabling it. So, what's the problem with that syntax?
This is briefly explained in the PEP 448 which introduces unpacking generalizations:
However, this may change in the future:
Taking a quote from the Py-Dev mailing list thread in which this feature was accepted:
(Emphasis mine)
I also took a peek at the Python issue tracker for this feature. I found an issue in which discussion took place while implementing it. The sequence of messages that helped them come to this realization starts here with a nice overview of the ambiguity introduced presented in msg234766 by GvR.
In fear of link-rot, I'm attaching the (formatted) message here:
Finally, as noted in the Abstract section of the corresponding PEP, this feature isn't completely ruled out:
So, we might get to see it sometime soon (definitely not 3.6, though :-) and I hope we do, they look nice.