3 ms·
I wonder why OrderedDict isn't outright deprecated (or reimplemented as a trivial wrapper over dict). You can get the first/last key of a 3.8 dict with dict.ke
by fyp 7y ago
I wonder why OrderedDict isn't outright deprecated (or reimplemented as a trivial wrapper over dict).
You can get the first/last key of a 3.8 dict with dict.keys() and reversed(dict.keys()) which you can then delete to reimplement OrderedDict.popitem.
Deleting a key and reinserting it will let you reimplement move_to_end.
The only cool thing that OrderedDict's implementation might be useful for is to move to front (or anywhere else not the back) but it doesn't expose that api.
- deniska 7y agoWhen OrderedDict is compared with another OrderedDict, it also checks whether the order of items is the same (this way also violating LSP, but that's another story), dict instances don't do that.
- travisjungroth 7y agoThanks, I just learned something.