In [13]:
def hanoi(source, target, auxiliary, n):
    if n > 0:
        hanoi(source, auxiliary, target, n - 1)
        target.append(source.pop())
        hanoi(auxiliary, target, source, n - 1)
    return source, target, auxiliary

In [15]:
A = [5, 4, 3, 2, 1]
B = []
C = []
print(hanoi(A, C, B, len(A)))


([], [5, 4, 3, 2, 1], [])

In [ ]: