[Tutor] Need to be taught a trick or two about printing in neat columns

Kent Johnson kent37 at tds.net
Thu Nov 2 20:51:48 CET 2006


Dick Moores wrote:
> Oops! Got overconfident. Didn't check to see if it actually printed 
> the whole list. It didn't. Left off "rad: radian", because there are 
> 46 items in the list (46%3 is 1, not 0). So now the only way I could 
> see to print all 46 was to add 2 empty dummies to make 48, which is 
> divisible by 3, and also modify the range in the second function. Is 
> there a better way, which is also a general solution that will work 
> when I subtract or add to the list? See the two  modified functions below.

There are almost enough grouping recipes in the cookbook to give them 
their own category. They tend to be fairly obscure. There is one in the 
comment on this page that would work for you:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496958

Or you could make a new list and pad it with spaces when you print, or 
use Markus' solution which is simple and clear.



More information about the Tutor mailing list