Do Ordered Dictionaries in Python Consume More Memory than Regular Dictionaries?

You are considered using ordered dictionaries in Python (e.g., because of the way they handle temporal data). Will your program use more memory this way compared to using a regular dictionary?

Yes. All things being equal, ordered dictionaries use more memory than normal dictionaries.

# You will see that Python 3's ordered dictionaries consume more memory than regular dictionaries
# This was adapted from

import sys
from collections import OrderedDict

x = OrderedDict()
y = {}

for i in range(1, 123456):
    x[i] = "filler text"
    y[i] = "filler text"

print("The size of the ordered dictionary is above and the regular dictionary is below.")

Leave a comment

Your email address will not be published.