0

Python has dictionary and OrderedDict. Why is OrderedDict not popular? Is it slow and inefficient? What will I lose if I switch from python dictionary to OrderedDict?

Ravikrn
  • 387
  • 1
  • 3
  • 19
  • Slower, certainly, and requiring more RAM if staying close to a normal dict's baseline big-O guarantees. A default dict implements only the necessary tree structure, which innately doesn't store order; to store order, you need either extra memory (and the time needed to keep the data in that extra memory updated, and refer to it in iteration) or a less efficient structure. – Charles Duffy Apr 24 '19 at 14:26
  • 2
    Or, dictionaries are inherently ordered now. 3.6 is implementation, 3.7 a feature – roganjosh Apr 24 '19 at 14:27
  • 3
    Since python 3.6+ dictionaries are ordered. https://stackoverflow.com/questions/39980323/are-dictionaries-ordered-in-python-3-6 – Daniel Lee Apr 24 '19 at 14:28
  • An excellent link, thank you! (Makes it clear that while Python 3.7's dicts still pay memory and performance costs for their ordering, these costs were paid out of the gains made in optimizations over the former implementation; so while they're faster and more memory-efficient than the dicts older versions of Python had, they're slower than a hypothetical unordered dict Python 3.x *could* have today). – Charles Duffy Apr 24 '19 at 14:31

0 Answers0