Gap buffer in Python