Jeremy Jones wrote:
> [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.
>
This is basically in following form :

a=iter(alist)
zip(a, a, a)
map(None, a , a, a)

The gurus(one of the bot) said that it is very bad in that there is no
contract saying zip/map would take one element from each iterable, in
that order. There is only contract for the output(tuples, one from each
iterables). Therefore, it is possible in some future version(though I
very much doubt) that it can be implemented that 4(or whatever number)
is taken from the iterables at a time, say for optimization purpose.

Reply via email to