zip unknown number of lists with Python for more than one list
Question: I need to do something very similar to what was asked here [How would you zip
an unknown number of lists in
Python?](http://stackoverflow.com/questions/5938786/how-would-you-zip-an-
unknown-number-of-lists-in-python), but in a more general case.

I have the following set up:

    
    
    a = [['a', '0', 'b', 'f', '78']]
    b = [['3', 'w', 'hh', '12', '8']]
    c = [['g', '7', '1', 'a0', '9'], ['45', '4', 'fe', 'h', 'k']]
    

I need to zip these lists together to obtain:

    
    
    abc =  [['a', '3', 'g', '45'], ['0', 'w', '7', '4'], ['b', 'hh', '1', 'fe'], ['f', '12', 'a0', 'h'], ['78', '8', '9', 'k']]
    

which I can generate with:

    
    
    zip(a[0], b[0], c[0], c[1])
    

But the lists `a,b,c` contain a number of sublists that will vary for
successive runs, so this "manual" way of expanding them won't work.

The closest I can get is:

    
    
    zip(a[0], b[0], *c)
    

Since unpacking a list with `*` in any other position than the last is not
allowed, the "ideal" expression:

    
    
    zip(*a, *b, *c)
    

does not work.

How could I zip together a number of lists with an unknown number of sublists?


Answer: `itertools.chain` to the rescue:

    
    
    import itertools
    
    z = list(zip(*itertools.chain(a, b, c)))
    

