Write code in a Google Doc to solve an editor large memory problem.
Implement editor(initial, operations) for a text document that may be too large for repeated whole-string copying. Each operation is ['insert', position, text] or ['delete', position, length], using zero-based character positions in the current document. Return the final string. Use a memory-conscious data structure that supports edits without rebuilding the complete document after every operation.
Examples: editor('abc', [['insert', 1, 'XY']]) returns 'aXYbc'; editor('abcdef', [['delete', 2, 3]]) returns 'abf'. Positions are valid, and deletions do not exceed the document length.
def editor(initial, operations):