def find_size(n, i):
    """Return a tuple, (k, i), where s is the size of the i-1'th set in the
       cardinally-ordered powerset of {0..n-1}, and i is the remaining index
       within the combinations of that size."""
if not 0 <= i < 2 ** n:
    raise ValueError('index is too large or small')
for k in range(n + 1):
    c = comb(n, k)
if c > i:
    return k, i
else:
    i -= c
Index into size ordered power set