def apply_filter(objs, selector, mode):
indices_to_delete = []<EOL>presumption = DELETE if mode == KEEP else KEEP<EOL>for i, obj in enumerate(objs):<EOL><INDENT>timer.log('<STR_LIT>' % selector)<EOL>marks = {k: mode for k in selector_to_ids(selector, obj, mode)}<EOL>timer.log('<STR_LIT>')<EOL>timer.log('<STR_LIT>')<EOL>filter_object(obj, marks, presumption=presumption)<EOL>timer.log('<STR_LIT>')<EOL>if obj is None:<EOL><INDENT>indices_to_delete.append(i)<EOL><DEDENT><DEDENT>for index in reversed(indices_to_delete):<EOL><INDENT>del objs[index]<EOL><DEDENT>
Apply selector to transform each object in objs.

    This operates in-place on objs. Empty objects are removed from the list.

    Args:
        mode: either KEEP (to keep selected items & their ancestors) or DELETE
              (to delete selected items and their children).