def generate_all_set(A, k):
if k == 1:
for i in A:
yield (i, )
else:
for i in A:
for j in generate_all_set(A, k - 1):
yield (i, ) + j
def Perm(A, k, n):
if k == n - 1:
yield tuple(A[:n])
else:
for i in range(k, n):
A[i], A[k] = A[k], A[i]
yield from Perm(A, k+1, n)
A[i], A[k] = A[k], A[i]