permutations을 이용해서 간단히 해결할 수 있었던 문제였다.
permutations
from itertools import permutations N = int(input()) arr = [i for i in range(1, N+1)] for i in permutations(arr, N): print(*i)