1

I know that the starred expression in python does this:

>>> a, *b = [1, 2, 3, 4]
>>> b
[2, 3, 4]

And this:

>>> def test(*args):
    print(args)
>>> test(1, 2, 3, 4)
(1, 2, 3, 4)

So what is it doing in this line? This line is supposed to group a list into sequential n-tuples.

zip(*[lst[i::n] for i in range(n)]) 

What does the star do? I tried to get its value, but it gives me an error:

>>> a = *[1, 2, 3, 4]
SyntaxError: can't use starred expression here

And when I tried it with a sample list:

>>> zip(*[1, 2,3, 4])
TypeError: zip argument #1 must support iteration

What does this mean? Aren't lists iterable? I must not be understanding a key concept with the star operator (if it's an operator). Please explain. (I'm using Python 3.5.2 if that helps.)

rassar
  • 5,412
  • 3
  • 25
  • 41
  • 1
    Note that the list comprehension results in a *nested* list being passed to `zip`; the error is telling you that the first element of your list is not iterable, not that the list itself is not iterable. – Daniel Roseman Dec 08 '16 at 22:01

0 Answers0