How to print variable length lists as columns in python?
Question: I need a way to print several lists of varying lengths as columns next to each
other tab delimited and with the empty cells remaining empty or containing
some fill character (e.g "-").

The methods attempted so far have not worked for lists of varying lengths and
numpy has not been working as I expected it.

To summarize:

    
    
    listname = [[1,2,3],[4,5,6,7,8],[9,10,11,12]]
    

printed as such in a .txt file:

    
    
    1    4    9
    2    5    10
    3    6    11
    -    7    12
    -    8    -
    


Answer: You can use
[`itertools.izip_longest`](https://docs.python.org/2/library/itertools.html#itertools.izip_longest).
To fill the `None` spaces in the longer sequences you can use `fillvalue`
(thanks @szxk):

    
    
    >>> import itertools
    >>> listname = [[1,2,3],[4,5,6,7,8],[9,10,11,12]]
    >>> for x in itertools.izip_longest(*listname, fillvalue="-"):
    ...     print '\t'.join([str(e) for e in x])
    ... 
    1   4   9
    2   5   10
    3   6   11
    -   7   12
    -   8   -
    

