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.
Using itertools.izip_longest:
for a, b in izip_longest(l1, l2, fillvalue=''):
print "{0:20s}\t{1:20s}".format(a, b)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With