How to optimize Python Dictionary for performance?

PythonProgramming

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.

raja
Published on 18-Apr-2018 13:13:36
Advertisements