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.

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019


Kickstart Your Career

Get certified by completing the course

Get Started