if r > n:
    return
indices = list(range(r))
yield tuple(pool[i] for i in indices)
while True:
    for i in reversed(list(range(r))):
        if indices[i] != i + n - r:
            break
else:
    return
indices[i] += 1
for j in range(i + 1, r):
    indices[j] = indices[j - 1] + 1
yield tuple(pool[i] for i in indices)
Понимание списка Python для возврата краевых значений списка