def record_delete_fields(rec, tag, field_positions_local=None):
if tag not in rec:<EOL><INDENT>return []<EOL><DEDENT>new_fields, deleted_fields = [], []<EOL>for position, field in enumerate(rec.get(tag, [])):<EOL><INDENT>if field_positions_local is None or position in field_positions_local:<EOL><INDENT>deleted_fields.append(field)<EOL><DEDENT>else:<EOL><INDENT>new_fields.append(field)<EOL><DEDENT><DEDENT>if new_fields:<EOL><INDENT>rec[tag] = new_fields<EOL><DEDENT>else:<EOL><INDENT>del rec[tag]<EOL><DEDENT>return deleted_fields<EOL>
Delete all/some fields defined with MARC tag 'tag' from record 'rec'.

:param rec: a record structure.
:type rec: tuple
:param tag: three letter field.
:type tag: string
:param field_position_local: if set, it is the list of local positions
    within all the fields with the specified tag, that should be deleted.
    If not set all the fields with the specified tag will be deleted.
:type field_position_local: sequence
:return: the list of deleted fields.
:rtype: list
:note: the record is modified in place.