Q:

How to print a table from lists with different lengths in Python

How do I print a table from two lists that have varying lengths (each list being a column)?
Example:
>>> l1=['Cat', 'Dog', 'Gorilla', 'Ladybug']
>>> l2=['Cat', 'Dog']
>>> print_chart(l1, l2)
Cat        Cat
Dog        Dog
Gorilla
Ladybug

Using rjust may be useful.

A:

Using itertools.izip_longest:
for a, b in izip_longest(l1, l2, fillvalue=''):
    print "{0:20s}\t{1:20s}".format(a, b)

