How to handle unpacking variable length extensions in Python2 ?
In Python3, if I have a variable length of subscriptions, I could use this idiom:
>>> x = [(1, 2,3,4,5), (2, 4,6), (3, 5,6,7,8,9)] >>> for i, *item in x: ... print (item) ... [2, 3, 4, 5] [4, 6] [5, 6, 7, 8, 9]
In Python2, this is an invalid syntax:
>>> x = [(1, 2,3,4,5), (2, 4,6), (3, 5,6,7,8,9)] >>> for i, *item in x: File "<stdin>", line 1 for i, *item in x: ^ SyntaxError: invalid syntax
By the way, this question is slightly different from the idiomatic way to unpack a list of variable lengths of maximum size n , where the solution requires knowledge of a fixed length.
And this question is specific to solving the problem in Python2.