#!/usr/local/bin/python3 sta = 'yamada' b = [('suzuki', 'satou'), ('yamada', 'tanaka'), ('tanaka', 'satou'), ('watanabe', 'suzuki')] ans = [] cur = sta ans.append(cur) bb = b.copy() for _ in range(len(bb)): if cur not in bb: raise for i, pair in enumerate(bb): if cur not in pair: continue cur = pair[1] if pair[0] == cur else pair[0] ans.append(cur) del bb[i] break print(ans)