4 ms·
It's already used that way for unpacking, e.g. >>> [x, *other] = range(10) >>> x 0 >>> other [1, 2, 3, 4, 5, 6, 7, 8, 9] So this instance of the syn
by duckerude 6y ago
It's already used that way for unpacking, e.g.
>>> [x, *other] = range(10)
>>> x
0
>>> other
[1, 2, 3, 4, 5, 6, 7, 8, 9]
So this instance of the syntax is not that novel. If it's a mistake, it's too late to fix it.
A unary asterisk before a name means the name represents a sequence of comma-separated items. If it's a name you're assigning to (LHS) that means packing the sequence into the name, if it's a name you're reading from (RHS) that means unpacking a sequence out of the name.
- heavenlyblue 6y agoYou can also do [a, * b] when constructing a list so that b would be injected into that list after a - makes total sense.