Another itertool function?

Steven Taschuk staschuk at telusplanet.net
Tue Apr 29 17:11:56 EDT 2003


Quoth Alex Martelli:
> Raymond Hettinger wrote:
>    ...
> > Here's another idea that was submitted:
> > 
> > def windowed(iterable, group=2):
> >     "returns (i[0], i[1], ... i[group-1]), (i[1], i[2], ... i[group]),
> 
> I think this would be perfect if the overlap between successively
> returned windows was also a parameter, rather than being fixed to 1.

Alexander Schmolck proposed such a function back in February [1];
his version included a "step" argument doing what you suggest.

In the discussion of whether such a function was useful enough to
be included in itertools, I provided several use cases [2], but
was unable to find a convincing one which needed a step other than
one.  Do you have one in mind?

[1] <http://groups.google.com/groups?selm=yfsbs172bjw.fsf%40black132.ex.ac.uk>

[2] <http://groups.google.com/groups?selm=mailman.1045851191.21005.python-list%40python.org>

-- 
Steven Taschuk             "[W]e must be very careful when we give advice
staschuk at telusplanet.net    to younger people: sometimes they follow it!"
                             -- "The Humble Programmer", Edsger Dijkstra





More information about the Python-list mailing list