| 114 | from collections.abc import MutableMapping |
| 115 | |
| 116 | class SortedDict(MutableMapping): |
| 117 | def __init__(self): |
| 118 | self.data = {} |
| 119 | |
| 120 | def __getitem__(self, key): |
| 121 | return self.data[key] |
| 122 | |
| 123 | def __setitem__(self, key, value): |
| 124 | self.data[key] = value |
| 125 | |
| 126 | def __delitem__(self, key): |
| 127 | del self.data[key] |
| 128 | |
| 129 | def __iter__(self): |
| 130 | keys = list(self.data.keys()) |
| 131 | keys.sort() |
| 132 | for key in keys: |
| 133 | yield key |
| 134 | |
| 135 | def __len__(self): |
| 136 | return len(self.data) |
| 137 | |
| 138 | |
| 139 | my_dict = SortedDict() |