[Python-ideas] Include partitioning in itertools

Andrew Barnert abarnert at yahoo.com
Tue Nov 3 20:06:14 EST 2015


On Nov 3, 2015, at 08:58, Sven R. Kunze <srkunze at mail.de> wrote:
> 
> Hey Lukas,
> 
> I agree both version (+ the n-part-partition-version of it) might be very useful to have.
> 
> But where do they go into?
> 
> itertools might be the right place for the iter_partition; but where to with the set_partition?

One more consideration: if you look at what's in itertools today, it isn't really everything you might want to do with and/or to produce iterators. Instead, it's (mostly) a collection of inner-loop building blocks that are accelerated with C code, and can be assembled together in pure Python to do almost everything you might want. The recipes give extensive examples of such things that are useful but don't need to be in the module itself. So, the question isn't just whether iter_partitions is like permutations in what it does, but whether it's like permutations in not having any more minimal building blocks—if there are such building blocks, it might be better to add those to itertools, and iter_partitions to the recipes.

Meanwhile, if you think there's a wider need for these functions than can be served by a blog post or ActiveState recipe, surely they should be on PyPI (whether or not they're in the stdlib—after all, if they're that useful, people will want them in 3.5 and 2.7). That also gives you a way to prove their usefulness—look at all these open source projects that use the library, and these comments from users saying "this really should be in the stdlib", and so on. At least for iter_partition, you might want to consider submitting it as an addition to more-itertools instead of posting your own library. He's already got a bunch of other stuff that's itertools-ish that may not belong in the stdlib (including all the recipes from the stdlib docs) but may still be useful enough for people to install the package.



More information about the Python-ideas mailing list