Show More
@@ -1253,6 +1253,9 b' class sortdict(collections.OrderedDict):' | |||||
1253 | >>> d2.update([(b'a', 2)]) |
|
1253 | >>> d2.update([(b'a', 2)]) | |
1254 | >>> list(d2.keys()) # should still be in last-set order |
|
1254 | >>> list(d2.keys()) # should still be in last-set order | |
1255 | ['b', 'a'] |
|
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 | def __setitem__(self, key, value): |
|
1261 | def __setitem__(self, key, value): | |
@@ -1268,6 +1271,14 b' class sortdict(collections.OrderedDict):' | |||||
1268 | for k, v in src: |
|
1271 | for k, v in src: | |
1269 | self[k] = v |
|
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 | class cowdict(cow, dict): |
|
1283 | class cowdict(cow, dict): | |
1273 | """copy-on-write dict |
|
1284 | """copy-on-write dict |
General Comments 0
You need to be logged in to leave comments.
Login now