Printing lists in columns
bdesth.quelquechose at free.quelquepart.fr
Tue Sep 4 05:31:36 CEST 2007
cjt22 at bath.ac.uk a écrit :
> Thanks guys, I really appreciate it. I have never used google groups
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
> 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 c.l.py and thanks for appreciating this group anyway !-)
> I have another question in relation to the izip_longest function (I
> 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
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
> works as I don't like adding code into my programs which I struggle to
> 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