직접 구현하려고 하는데, 이미 파이썬에서 제공하고 있었다.

import itertools
inp_list = [4, 5, 6]
permutations = list(itertools.permutations(inp_list))
print(permutations)
[(4, 5, 6), (4, 6, 5), (5, 4, 6), (5, 6, 4), (6, 4, 5), (6, 5, 4)]

순열 길이의 기본값은 입력 값의 길이가 된다. 만약 길이를 직접 지정하려면 파라미터를 추가하면 된다.

import itertools
inp_list = [1, 2, 3]
permutations = list(itertools.permutations(inp_list, r=2))
print(permutations)
[(4, 5), (4, 6), (5, 4), (5, 6), (6, 4), (6, 5)]

참고 자료

https://www.delftstack.com/ko/howto/python/how-to-generate-all-permutations-of-a-list-in-python/