4 ms·
OrderedDict is slow and expensive though: it maintains ordering through a doubly linked list. It has useful features for manipulating ordering but while I've r
by masklinn 7y ago
OrderedDict is slow and expensive though: it maintains ordering through a doubly linked list.
It has useful features for manipulating ordering but while I've regularly needed had use for maintaining insertion ordering I can't remember ever needing to move items around within a map.
- hencoappel 7y agoIf memory serves me correctly, ever since dicts became ordered the OrderedDict simply became a subclass of dict, so it will have exactly the same performance characteristics.
- edflsafoiewq 7y agoYup. >>> isinstance(OrderedDict(), dict) True
- masklinn 7y agoThat was already the case in python 2.7 or 3.1.
- masklinn 7y agoOrderedDict was always a subclass of dict maintaining additional information (which is not free, it has to store and manipulate two pointers per entry). It remains so today, ordereddict is not an alias or trivial facade to the normal dict because it has to maintain its doubly linked list and implement a bunch of additional operations based on that e.g. pop first or move to end.