[Python-ideas] Include partitioning in itertools

Sven R. Kunze srkunze at mail.de
Sun Nov 1 12:14:20 EST 2015


Hi Albert,

sounds useful. I can remember needing it myself.

On 01.11.2015 12:08, Albert ten Oever 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.

This operates over iterables, right? So, it's not quite about sets alone.

> 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.

Not quite sure if I understand the implementation. Reading this 
http://mathworld.wolfram.com/BellNumber.html for the given example of 6, 
it should have 203 possible partitions. What am I missing?

The implementation over there reads as if one gets a list of all 
possible partitions. Picking a specific subset ("all 4-part-partitions") 
could be useful as well.

> Definitions of partitions: 
> http://mathworld.wolfram.com/SetPartition.html or 
> https://en.wikipedia.org/wiki/Partition_of_a_set
>
> Humble regards,
>
> Albert.

Best,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151101/07c9e4e0/attachment.html>


More information about the Python-ideas mailing list