istep() addition to itertool? (Was: Re: Printing n elements per line in a list)
Justin Azoff
justin.azoff at gmail.com
Mon Aug 21 01:17:53 EDT 2006
Rhamphoryncus wrote:
> I've run into this problem a few times, and although many solutions
> have been presented specifically for printing I would like to present a
> more general alternative.
[snip interesting istep function]
> Would anybody else find this useful? Maybe worth adding it to itertool?
yeah, but why on earth did you make it so complicated?
def istep(iterable, step):
a=[]
for x in iterable:
if len(a) >= step:
yield a
a=[]
a.append(x)
if a:
yield a
--
- Justin
More information about the Python-list
mailing list