[Python-ideas] Include partitioning in itertools

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


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.

On Sun, Nov 1, 2015 at 5:49 PM, David Mertz <mertz at gnosis.cx> wrote:

> This doesn't make sense to me for `itertools`.  There is no way to
> "partition" an infinite sequence in the style of the recipe you show (nor
> any sensible one I can think of).  I think a better name would be
> `powerset()` anyway; but in either case, it's not an `itertools` type of
> operation.
>
> I think what might be more useful is to make a mix-in class that gave
> concrete collections a `.powerset()` method that preserved the types of the
> original collection.  I think you can even do this as an iterable without
> having to concretize the whole set of subsets (but not from an iterable,
> from a concrete collection, as input).
>
> On Sun, Nov 1, 2015 at 3:08 AM, Albert ten Oever <agtoever at hotmail.com>
> wrote:
>
>> Hi all,
>>
>> I really hope this isn't proposed before - I couldn't find anything in
>> the archives.
>>
>> I want to propose to include a 'partition' (mathematically more correct:
>> a set partition) function in itertools. To my knowledge, partitioning of a
>> set (iterable) is quite a common thing to do and a logic extension of the
>> combinatoric generators in itertools.
>>
>> It is implemented as a Python recipe (
>> http://code.activestate.com/recipes/576795-partitioning-a-sequence/). I
>> found that implementing a partition generator of an iterable isn't very
>> straightforward, which, in my opinion, strengthens the case for
>> implementing it as a separate function.
>>
>> Definitions of partitions: http://mathworld.wolfram.com/SetPartition.html
>>  or https://en.wikipedia.org/wiki/Partition_of_a_set
>>
>> Humble regards,
>>
>> Albert.
>>
>> _______________________________________________
>> 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.
>



-- 
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/202c8c5c/attachment.html>


More information about the Python-ideas mailing list