[EMAIL PROTECTED] wrote:

Jeremy Jones wrote:
Jeff Watkins wrote:

Using a KID template, I'd like to format a list of elements in a
grid. For example:

[ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]

rendered in a table as:

.-----------.
: 1 : 2 : 3 :
:---+---+---:
: 4 : 5 : 6 :
:---+---+---:
: 7 : 8 : 9 :
'-----------'

This would be simple using JSP or ASP, but I'm drawing a blank on how
to do this in Kid.

(Don't want to use templates, but that's life.)

I typically do it something like this:

<?python
chunked_list = map(None, *[iter(some_list)]*2)
?>

A really cool one-liner to partition any iterables. Though this is
discussed over at c.l.py and condamned by the gurus that it is bad and
has a very remote possibility that it may break in some future version
of python.

I'm usually not one for "clever" over clear code, but I prefer this over any alternative I've found. I'd be interested to read what "the gurus" are condemning it for. If it's for other reason other than that it probably will break with the advent of Python 3000 (which may be soon now that Guido's at Google and can probably work on it more), I think the condemnation is mostly groundless. But I'm willing to be corrected.

- jmj

Reply via email to