itertools candidate: warehouse()

Carlos Ribeiro carribeiro at gmail.com
Mon Oct 18 20:33:35 EDT 2004


On Tue, 19 Oct 2004 00:19:43 +0100, Michael Hoffman
<m.h.3.9.1.without.dots.at.cam.ac.uk at example.com> wrote:
> Robert Brewer wrote:
> >
> > What do you all think? I've been using a class-based variant of this in
> > production code (business app) for six months now, and have found it
> > extremely helpful. I saw a pointer to itertools today and figured a
> > function-based version might be nice to include in that module someday.
> 
> Could you give a real-world example of its use?

I think Robert is referring to a conversation where I took part
earlier today. My problem was to evaluate some alternatives for a
recursive generator. The problem with the recursive generator is that
one has to loop over the nested generators simply to yield back the
results to the original caller; for example, if you are at depth three
on the recursive generator, each yield in the inner generator will in
turn generate two more yields on as you go up the recursion stack,
before finally yielding the value to the original caller.

The warehouse may be useful in that situation; the solution is not
exactly the same, but it allows to express similar ideas and may be a
good alternative when designing generator-based code for complex
structures.

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro at gmail.com
mail: carribeiro at yahoo.com



More information about the Python-list mailing list