[Python-ideas] Include partitioning in itertools

David Mertz mertz at gnosis.cx
Sun Nov 1 22:42:42 EST 2015


I'm surprised to have just noticed that `itertools` is oddly broken this
way (under Python 3.4.3):

This is perfectly happy:

>>> def fibs():

    a, b = 1, 1
    while True:
        yield b
        b, a = a+b, b
...
>>> f = ((a,b) for a in fibs() for b in fibs())
>>> next(f)
Out[3]: (1, 1)
>>> next(f)
Out[4]: (1, 2)
>>> next(f)
Out[5]: (1, 3)

And yet this freezes be greedily trying to go through the infinite iterator:

>>> from itertools import product
>>> product(fibs(), fibs())


On Sun, Nov 1, 2015 at 6:37 PM, Brendan Barnwell <brenbarn at brenbarn.net>
wrote:

> On 2015-11-01 17:58, David Mertz wrote:
>
>> Oh, yeah... I see what you are asking for isn't quite the same thing as
>> power set.  But still, it's not something you can do in finite time with
>> infinite iterators (nor in tractable time with *large* iterators).  So
>> `itertools` isn't where it belongs.
>>
>
>         I don't think that reasoning is sound.  Itertools already includes
> several combinatoric generators like permutations and combinations, which
> aren't computable for infinite iterators and which take intractable time
> for large finite iterators.
>
> --
> Brendan Barnwell
> "Do not follow where the path may lead.  Go, instead, where there is no
> path, and leave a trail."
>    --author unknown
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151101/78ea3879/attachment-0001.html>


More information about the Python-ideas mailing list