Hướng dẫn python append to ordereddict
Ngày đăng:
24/09/2022
Trả lời:
0
Lượt xem:
195
Add the new item to the original items, sort, make a new dict:
Or a bit more involved option:
Sorted dict that maintains key sorted orderI couldn't figure out how to make an OrderedDict subclass work - it has a number of attributes that get name mangled - only one or two methods need to be overridden and I didn't want to spend the time figuring out the name-mangling aspect. So just copy the whole OrderedDict class from the source from here - to here into a separate module, so you can import it, and include these imports.
Then change the following in the class:
If using bisect doesn't seem worthwhile just traverse the linked list till the insertion point is found. (All the other changes listed above still apply)
Usage |