Show More
@@ -1253,6 +1253,9 b' class sortdict(collections.OrderedDict):' | |||
|
1253 | 1253 | >>> d2.update([(b'a', 2)]) |
|
1254 | 1254 | >>> list(d2.keys()) # should still be in last-set order |
|
1255 | 1255 | ['b', 'a'] |
|
1256 | >>> d1.insert(1, b'a.5', 0.5) | |
|
1257 | >>> d1 | |
|
1258 | sortdict([('a', 0), ('a.5', 0.5), ('b', 1)]) | |
|
1256 | 1259 | ''' |
|
1257 | 1260 | |
|
1258 | 1261 | def __setitem__(self, key, value): |
@@ -1268,6 +1271,14 b' class sortdict(collections.OrderedDict):' | |||
|
1268 | 1271 | for k, v in src: |
|
1269 | 1272 | self[k] = v |
|
1270 | 1273 | |
|
1274 | def insert(self, position, key, value): | |
|
1275 | for (i, (k, v)) in enumerate(list(self.items())): | |
|
1276 | if i == position: | |
|
1277 | self[key] = value | |
|
1278 | if i >= position: | |
|
1279 | del self[k] | |
|
1280 | self[k] = v | |
|
1281 | ||
|
1271 | 1282 | |
|
1272 | 1283 | class cowdict(cow, dict): |
|
1273 | 1284 | """copy-on-write dict |
General Comments 0
You need to be logged in to leave comments.
Login now