for x in old_elements[:]: for y in new_elements[:]: if field.match(x, y): yield field, x, y old_elements.remove(x) new_elements.remove(y)