Re: [Tutor] Formatting output into columns

2007-08-31 Thread Scott Oertel
Luke Paireepinart wrote: > Scott Oertel wrote: >> Someone asked me this question the other day, and I couldn't think of >> any easy way of printing the output besides what I came up with pasted >> below. >> >> So what you have is a file with words in it as such: >> >> apple >> john >> bean >> joke

Re: [Tutor] Formatting output into columns

2007-08-30 Thread Luke Paireepinart
Scott Oertel wrote: > Someone asked me this question the other day, and I couldn't think of > any easy way of printing the output besides what I came up with pasted > below. > > So what you have is a file with words in it as such: > > apple > john > bean > joke > ample > python > nice > > and you w

Re: [Tutor] Formatting output into columns

2007-08-30 Thread Kent Johnson
Alan Gauld wrote: > "Scott Oertel" <[EMAIL PROTECTED]> wrote >> Do you have any good documentation that could shed some more light >> on >> exactly how to use format strings in such a way? > > The docs contain the basic documentation http://docs.python.org/lib/typesseq-strings.html > # there's

Re: [Tutor] Formatting output into columns

2007-08-30 Thread Alan Gauld
"Scott Oertel" <[EMAIL PROTECTED]> wrote >> 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. >> > Do you have any good documentation that cou

Re: [Tutor] Formatting output into columns

2007-08-30 Thread Kent Johnson
Scott Oertel wrote: > #!/usr/bin/env python > > data = {} > lrgColumn = 0 > > for line in open("test.txt","r").read().splitlines(): > char = line[0].lower() > if not char in data: > data[char] = [line] > else: > data[char].append(line) I like data.setdefault(char,

Re: [Tutor] Formatting output into columns

2007-08-30 Thread Scott Oertel
Alan Gauld wrote: > "Scott Oertel" <[EMAIL PROTECTED]> 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

Re: [Tutor] Formatting output into columns

2007-08-30 Thread Alan Gauld
"Scott Oertel" <[EMAIL PROTECTED]> 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