Printing lists in columns

Bruno Desthuilliers bdesth.quelquechose at
Tue Sep 4 05:31:36 CEST 2007

cjt22 at a écrit :
> Thanks guys, I really appreciate it. I have never used google groups
> before

Actually, comp.lang.python is a usenet newsgroup, not a google group. 
Google only gives you a web fronted (and archives...) for that group. I 
personnaly access it with my MUA.

> and am so impressed with how helpful you all are. It is also lovely
> that
> none of you mock my little knowledge of Python but just want to
> improve it.

Well... Why should we mock ? We've all been beginners, and we're still 
all beginners in a domain or another.

But welcome to and thanks for appreciating this group anyway !-)

> I have another question in relation to the izip_longest function (I
> persume
> this should be within the same topic).
> Using this funciton, is there a way to manipulate it so that the
> columns can be formated
> tabular i.e. perhaps using something such as str(list).rjust(15)
> because currently the columns
> overlap depending on the strings lengths within each column/list of
> lists. i.e. my output is
> currently like:
> 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
> I am struggling to understand how the izip_longest function works

What's bothering you ?-)

Sorry, just joking. This code uses some 'advanced' stuffs like closures, 
HOFs and generators/iterators, so it's obviously not that simple to grok 
- FWIW, I myself had to read it at least thrice to understand it.

> and thus don't really know how it could be manipulated to do the
> above.

FWIW, you don't have - and IMHO should not try - to do this within 
izip_longest, which is a generic function.

> It would be much apprecited if somoene could also explain how
> izip_function
> works as I don't like adding code into my programs which I struggle to
> understand.
> Or perhaps I have to pad out the lists when storing the Strings?

I'd personnaly do the formatting just before printing.

More information about the Python-list mailing list