Exercise 2 solution def cross_over_many(mat, pat, points): a, b = mat, pat for p in sorted(points): a, b = a[:p] + b[p:], b[:p] + a[p:] return a, b mat, pat = "AAAAAAAAAA", "bbbbbbbbbb" for points in ([4], [3, 7], [2, 5, 8], []): a, b = cross_over_many(mat, pat, points) ok = all(set(pair) == {"A", "b"} for pair in zip(a, b)) print(points, a, b, ok) Output: [4] AAAAbbbbbb bbbbAAAAAA True [3, 7] AAAbbbbAAA bbbAAAAbbb True [2, 5, 8] AAbbbAAAbb bbAAAbbbAA True [] AAAAAAAAAA bbbbbbbbbb True Reading it: Each swap exchanges the tails after the point, so at every position the two results hold the two original letters between them, in one order or the other.