Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
11-liner: you cannot copy a shallow version, so deepcopy it solution in Clear category for Text Editor by Stensen
from copy import deepcopy
class Text:
text = font = ''
def write(self, text): self.text += text
def set_font(self, font): self.font = f'[{font}]'
def restore(self, version): self.text, self.font = version.text, version.font
show = lambda self: f'{self.font}{self.text}{self.font}'
class SavedText:
def __init__(self): self._versions = []
def save_text(self, text): self._versions.append(deepcopy(text))
get_version = lambda self, number: self._versions[number]
Oct. 17, 2020