python permutation (1) 썸네일형 리스트형 Python 순열(Permutation) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 # 1 ~ n 까지의 숫자가 있을 때 나열할 수 있는 경우의 수 혹은 경우 def perm(a): length = len(a) if length == 1: return [a] else: result = [] for i in a: b = a.copy() b.remove(i) b.sort() for j in perm(b): j.insert(0, i) if j not in result: result.append(j) return result if __name__ == "__main__": num = int(input('1부터 n까지 자연수를 나열하는 순열을 구합니다. n 을 입력하세요 : ')) a.. 이전 1 다음