<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def apply(diff, recs, strict=True):
 """ Transform the records with the patch. May fail if the records do not match those expected in the patch. """

    index_columns = diff['_index']
    indexed = records.index(copy.deepcopy(list(recs)), index_columns)
    _add_records(indexed, diff['added'], index_columns, strict=strict)
    _remove_records(indexed, diff['removed'], index_columns, strict=strict)
    _update_records(indexed, diff['changed'], strict=strict)
    return records.sort(indexed.values())