[Tutor] Formatting output into columns

Alan Gauld alan.gauld at btinternet.com
Thu Aug 30 22:58:44 CEST 2007


"Scott Oertel" <freebsd at scottevil.com> wrote

> and you want to sort and output the text into columns as such:
>
> a              p               j             b              n
> apple      python     john       bean       nice
> ample                      joke
>
> and this is what works, but I would also like to know how to wrap 
> the
> columns, plus any ideas on a better way to accomplish this.

Use format strings. You can calculate the column widths by analyzing
the data then create a format string for the required number of 
columns.
Finally insert the data on each row from a tuple.


HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list