2013/2/25 Greg Ewing
João Bernardo wrote:
Python already supports this odd syntax
a, b, *[] = iterable
because it interprets the [] not as an empty list, but as an empty "list of identifiers". Maybe it could be used for something useful.
No, because it already has a meaning: there must be no more values left in the sequence.
Why have two things with the same meaning? a, b = iterable a, b, *[] = iterable Both are the same... The *[] thing is about 100% useless right now. And the empty "list" syntax is so not used it was possible to segfault pypyhttps://bugs.pypy.org/issue1364 by putting that in a for loop.
BTW, the del syntax has the same "problem"
del a, b, (c,), [d], []
Or just
[] = iterable
The surprising thing is that a special case seems to be made for ():
() = [] File "<stdin>", line 1 SyntaxError: can't assign to ()
It's surprising because () and [] are otherwise completely interchangeable for unpacking purposes
That's what I'm saying... [] and () during unpaking aren't the same thing when they normally should... The same happens with the "del" syntax! One can think about this to see if an iterable is empty and raise an error if it is not: [] = iterable But *[], = iterable Has the exact same meaning and is very cryptic. BTW: This is the code golf winner to make a list of chars: *s, = 'string'