Printing lists in columns

Ryan Ginstrom software at ginstrom.com
Wed Sep 5 04:44:47 EDT 2007


> On Behalf Of cjt22 at bath.ac.uk
> bo, daf, da
> pres, ppar, xppc
> magnjklep, *, dsa
> *, *, nbi
> 
> But I want it justified, i.e:
> 
> bo       ,  daf,  da
> pres     , ppar,  xppc
> magnjklep,    *,  dsa
> *        ,    *,  nbi

Once you have a nice rectangular list of lists, you might want to take a
look at my padnums module.

# Usage:
import padnums
import sys

table = [row for row in izip_longest(*d, fillvalue='*')]
padnums.pprint_table(sys.stdout, table)

Code described here, with link to module:
http://ginstrom.com/scribbles/2007/09/04/pretty-printing-a-table-in-python/

Regards,
Ryan Ginstrom




More information about the Python-list mailing list