How to optimize Python Dictionary for performance?


dicts in python are heavily optimized. Creating a dict from N keys or key/value pairs is O(N), fetching is O(1), putting is amortized O(1), and so forth. You don't need to optimize them explicitly. You can be sure of this as python under the hood implements its own classes using dicts.

Don't compare lists/tuples to dicts/sets though as they solve different problems.

Published on 18-Apr-2018 16:43:36