4 ms·
Ordereddict has been available for ages. Why should I pay for the overhead in the 98% of the cases where I don't need it.
by dbcurtis 9y ago
Ordereddict has been available for ages. Why should I pay for the overhead in the 98% of the cases where I don't need it.
- jsmeaton 9y agoKeeping the dict ordered is actually faster. There’s a link to a YouTube talk a little upthread that discusses the algorithms used. It’s really interesting.
- alexbecker 9y agoThe new dict implementation was introduced in 3.5 (with forced order randomization, which was removed in 3.6) because it is faster and uses less memory than the previous non-ordered dict. Ordering is merely a nice byproduct. So you're not paying any penalty. OrderedDict is fundamentally different because it is designed to allow inserting/removing keys in the middle of the ordering in O(1) time. It does not use the new dict under the hood, or vice-versa.