Generating all combinations
steven at REMOVE.THIS.cybersource.com.au
Thu Jun 4 05:48:11 CEST 2009
On Wed, 03 Jun 2009 20:27:56 -0700, Raymond Hettinger wrote:
>> > What, no partitions?
> Simpler version:
> def partition(s):
> n = len(s)
> parts = range(1, n)
> for i in range(n):
> for div in combinations(parts, i):
> print map(s.__getslice__, chain(, div), chain(div,
Raymond, as perhaps *the* principle contributor to itertools, do you feel
that the combinatorics-related tools should be in their own module? Or is
that dividing the module too fine?
Would you consider moving permutations() and friends into a module
together with functions for calculating the number of permutations etc?
e.g. permutations(iterable[, r]) --> permutations object
nPr(n, r) --> int
More information about the Python-list