def next_combination(n, c):
    if c[-1] == n - len(c) + 1:
        raise ValueError('no more combinations')
for i in range(len(c) - 1, -1, -1):
    if i == 0 or c[i] < c[i - 1] - 1:
        return c[:i] + (c[i] + 1,) + tuple(range(len(c) - 2 - i, -1, -1))
Index into size ordered power set