m = [(1,2,3), (4,5,6)] |
How does this work? Well, Norvig says that "f(*m) is like apply(f,m)," and I know that apply(f,m) feeds the elements of m to the function f, where in this case f is zip. If we do zip on two lists:
L = list('abcde') |
However, feeding the nested list directly to zip does not do what we want:
nestedL = [L,R] |
But this does:
apply(zip, nestedL) |
So the next question is, how does f(*args) turn into apply(f,args)?
def f(*T): |
T is a tuple containing nestedL as its first element. Here is where I lose the trail. It makes my head spin. But zip(*m) really is a neat trick to remember.