A: 

A HashMap using a String (Or even a character) as the key (Letter of the alphabet) and a array as the value.

Richie_W
Yes but how to split them on equal columns?
omoto
A: 

Looks like a website, probably an overview.

The answer is: templates and php

WebDevHobo
+1  A: 

I think you mean something like this:

items = sorted(file("items.txt").readlines())

current = ""
clines = 0
maxlines = 50

print "<table><tr><td>"
for i in items:
    if i[0].upper() != current:
     current = i[0].upper()
     print "<h1>", current, "</h1>"
    clines += 1
    if clines >= maxlines:
     print "</td></td>"
     clines = 0
    print i

print "</td></tr></table>"

Surely the HTML sucks, but that's the idea, when you exceed the maximum lines per column, switch to the next column.

If you want to make sure that a column always starts with a heading, then you should switch to the next column when the current number of lines plus the size of the next group exceeds the maximum number of lines per column.

fortran
One requirement I should include all letters to this list, in your sample if I right understand it's impossible if items.txt will be without any letter
omoto
It's easy to add a check for that and add the missing headings... just check the ordinal number of the letters to see if they're consecutive or not.
fortran
A: 

I would probably approach it in the following manner:

  1. If the input list is unsorted, find a technique (LINQ, etc.) to group and sort your item groups and items. That doesn't really seem to be your question here, although I'm open to correction - there are dozens of techniques for doing that, so it should be a popular question on its own...
  2. Identify the number of desired columns. We could even try different numbers of columns later in the algorithm, to try to get "best-fit".
  3. Divide the total number of detail items (possibly including the headers as well - I'm designing this on my feet...) by the number of columns. This will be the approximate number of items we want in each column.
  4. Starting from the left, place items into the column until adding another group would run over the number of items per column. (probably need to consider the possibility of one freakishly-large group that fills an entire column by itself...) At this point, we need to decide whether the next group goes in this column or the next one. I'd suggest something like this: if the break point within this group is in the upper half - i.e. more items in the group would be below the desired cut-off line than above it - go to the next column. Otherwise, add the group to the current column. Obviously if we are in the last column, there is no "next" column so we just add it to this one.

The hope is that using this technique - allowing each column to overflow slightly - will balance out over time and space. Otherwise, we just keep pushing groups to the next column and our final column ends up significantly longer than the others.

GalacticCowboy
A: 
omoto
Looks nice, I'm glad to have been helpful :-)
fortran