Message 81026 - Python tracker (original) (raw)
To parallel the functions in itertools, add:
math.combinations(n,r) --> n! / r! / (n-r)! when 0 <= r <= n or zero when r > n.
math.permutations(n,r) --> n! / (n-r)! when 0 <= r <= n or zero when r > n.
math.combinations_with_replacement(n,r) --> (n+r-1)! / r! / (n-1)! when n > 0. And when n==0, return 0 if r>0 else 1.
These will enable an itertools user to compute the length of those iterators. It will also serve for general probability computations. Likewise, it produce binomial coefficients and multiset partitions.
Since, the math module is where we put the factorial() function, it is the logical place for the combinatoric counting functions.