[Python] 1.5 lines per function bests 98%+89% with explanation
The idea is simple. \n1. The array-like data structure with default value 0 can be implemented as a default dictionary self.dict with default value 0.\n2. The s
The idea is simple. \n1. The array-like data structure with default value 0 can be implemented as a default dictionary `self.dict` with default value 0.\n2. The snapshots `self.snap_arr` is a list of such default dictionaries. \n3. The `snap()` function appends one element to `self.snap_arr`, whose length is exactly the "total number of times we called `snap()`".\n```\nclass SnapshotArray:\n    def __init__(self, length: int):\n        self.dict = defaultdict(int)\n        self.snap_arr = []\n\t\t\n    def set(self, index: int, val: int) -> None:\n        self.dict[index] = val\n\t\t\n    def snap(self) -> int:\n        self.snap_arr.append(self.dict.copy())\n        return len(self.snap_arr) - 1\n\t\t\n    def get(self, index: int, snap_id: int) -> int:\n        return self.snap_arr[snap_id][index]\n```
['Python', 'Python3']