a = [1 + 4j, 7 + 0j, 3 + 6j, 9 + 2j, 5 + 8j]
b = [2 + 5j, 8 + 1j, 4 + 7j, 0 + 3j, 6 + 9j]
keyed_a = ((n.real, n) for n in a)
keyed_b = ((n.imag, n) for n in b)
from itertools import chain
sorted_ab = zip(*sorted(chain(keyed_a, keyed_b), key=lambda t: t[0]))[1]
sorted_ab
Iterate over a pair of iterables, sorted by an attribute