Issue
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.
Solution
Using itertools.izip_longest
:
for a, b in izip_longest(l1, l2, fillvalue=''):
print "{0:20s}\t{1:20s}".format(a, b)
Answered By - Björn Pollex
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.