Here’s an interesting fact about Python Dictionaries ⚡
Python Dictionaries maintain the insertion order of the keys. This means when you iterate over the keys of the dictionary you will always get them in the order in which they were inserted.
They do this by maintaining an array named dk_entries to hold the incoming entries (in order) and another array called dk_indices to store the indices. Pretty neat implementation 🔥
You can check the CPython source code to dive deep into the implementation details. Linking the actual line of implementation here
Python Dictionary Internals: https://lnkd.in/gG87u4g4
Also, here’s a quick video of me explaining how Python optimizes string using String interning
watch - youtu.be/QpGK69LzfpY
⚡ I keep writing and sharing these engineering nuggets, so if you are keen on learning them, follow along.
arpitbhayani.me/courses