How expensive are Python dictionaries to handle?


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 dont 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.

Updated on: 30-Jul-2019

148 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements