>>> C = iter(A + [b for b in B if b not in A]) >>> [next(C) if e in A+B else e for e in arr] [1, 2, 4, 5, 7, 8, 3, 6, 9, 10]