16 Oct
2016
16 Oct
'16
5:18 a.m.
Steven D'Aprano wrote:
Are you now supporting my argument that starring the list comprehension expression isn't meaningful?
The context it's in (a form of list display) has a clear meaning for a comma-separated list of values, so there is a reasonable interpretation that it *could* be given.
py> iterable = [(1, 'a'), (2, 'b')] py> [(100, *t) for t in iterable] [(100, 1, 'a'), (100, 2, 'b')]
The * there is in the context of constructing a tuple, not the list into which the tuple is placed. The difference is the same as the difference between these:
t = (10, 20) [1, (2, *t), 3] [1, (2, 10, 20), 3] [1, 2, *t, 3] [1, 2, 10, 20, 3]
-- Greg