[Python-Dev] A `cogen' module [was: Re: PEP 218 (sets); moving set.py to Lib]
Guido van Rossum
Wed, 28 Aug 2002 10:27:30 -0400
> Special-casing the 2 argument case helps a lot. It brings the performace
> within 50% of nested loops which means that if you actually do something
> inside the loop the overhead is quite negligible.
Hm, I tried that and found no difference. Maybe I didn't benchmark right.
> Ahh... re-iterability again...
> This is a good example of a function that *fails silently* for non
> re-iterable arguments.
This failure is hardly silent IMO: the results are totally bogus,
which is a pretty good clue that something's wrong.
> Slurping the tail into a list loses the lazy efficiency of this function.
> One of the ways I've used this function is to scan combinations until a
> condition is satisfied. The iteration is always terminated before reaching
> the end. Reading ahead may waste computation and memory.
I don't understand. The Cartesian product calculation has to iterate
over the second argument many times (unless you have it iterate over
the first argument many times). So a lazy argument won't work. Am I
> All I want is something that will raise an exception if any argument but
> the first is not re-iterable (e.g. my reiter() proposal). I'll add list()
> to the argument myself if I really want to. Don't try to guess what I
Actually, I don't want to reiterate this debate.
--Guido van Rossum (home page: http://www.python.org/~guido/)