조합
N = 4
R = 3
lst = [1,2,3,4]
choose = []
def combination(index, level):
if level == R:
print(choose)
return
for i in range(index, N):
choose.append(lst[i])
combination(i+1, level+1)
choose.pop()
combination(0,0)
from itertools import combinations
print(list(combinations(lst, 3)))
순열
N = 10
R = 3
lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
check = [False] * N
choose = []
def permutation(level):
if level == R:
print(choose)
return
for i in range(0, N):
if check[i] == True:
continue
choose.append(lst[i])
check[i] = True
permutation(level+1)
check[i] = False
choose.pop()
permutation(0)