Add pbotlib.odds.
[poker.git] / pbot / combinations.py
1 """Assorted useful combinatorics.
2 """
3
4
5 def xunique_combinations(items, n):
6     """Iterate through unordered, length `n` subsets of `items`.
7
8     >>> for c in xunique_combinations([1, 2, 3], 2):
9     ...     print c
10     [1, 2]
11     [1, 3]
12     [2, 3]
13     """
14     if n==0: yield []
15     else:
16         for i in xrange(len(items)):
17             for cc in xunique_combinations(items[i+1:],n-1):
18                 yield [items[i]]+cc