#! /usr/local/bin/python3 def hanoi1(n, a, b, c): if n == 0: return yield from hanoi1(n-1, a, c, b) yield a, b yield from hanoi1(n-1, c, b, a) def hanoi(n): yield from hanoi1(n, 'a', 'b', 'c') for a, b in hanoi(7): print(f'{a} => {b}')