How to print a sorted list as a multi-column table
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sun May 25 00:38:59 EDT 2008
En Fri, 23 May 2008 15:03:16 -0300, Mensanator <mensanator at aol.com> escribió:
> On May 23, 10:30 am, Sverker Nilsson <s... at sncs.se> wrote:
>> Why are tables formatted like the following, when sorted? (Both in
>> linux eg ls, ftp help, and in Python help() when listing (eg)
>> modules))
>>
>> (1)
>>
>> a g m s
>> b h n t
>> c i o u
>> d j p v
>> e k q
>> f l r
>
> Because it's easier to read when the items have more
> than one letter. Have a look at a dictionary.
I agree with the OP. Dictionaries have two or more columns, but they span several *small* pages. The index above asumes an infinite page height, like a dictionary with all pages joined together making a single giant page. If dictionaries were sorted like the index above, "Python" could appear in the first page, and "Django" in the last one...
>> In a pager, if you want to limit the number of lines output at a time,
>> then yo'd see with (1) (if artifically limiting output to 2 lines):
>>
>> a g m s
>> b h n t
>>
>> So to see the f item you would have to scroll down all the way. The
>> number of times you would have to scroll down is in completely
>> unrelated to the item's position in sort order. That seems to defeat
>> the purpose of sorting in the first place. It feels strange, to me at
>> least. Anybody had the same feeling?
>
> No.
I do!
>> Well, what's the rationale (if any) for using the layout (1)?
>> Wouldn't layout (2) be better? And/or would it be confusing /
>> non-pythonic / non-unlixonic if a program used the (2) layout instead?
> The obvious solution is to do both, like the DOS directory
> command:
I'd use layout (1) *but* on a single page at a time. The layout you see on real dictionaries, or printed books.
--
Gabriel Genellina
More information about the Python-list
mailing list