CPython's dict Implementation in C: Combined Tables, Split Keys, and the Probe Sequence
CPython’s dict is a hash table with a twist: compact and insertion-ordered since 3.6, and able to share a single keys object across thousands of instances.
CPython’s dict is a hash table with a twist: compact and insertion-ordered since 3.6, and able to share a single keys object across thousands of instances.
There’s exactly one Ellipsis, and it’s immortal: a static struct initialized with a refcount of 3«30 so that no increment or decrement can ever bring it to zero.
enumerate, zip and reversed don’t build lists: they’re lazy C iterators that reuse one result tuple and mutate it in place, so a for loop over them allocates almost nothing.
Exceptions are ordinary GC-tracked objects with a shared PyException_HEAD prefix, plus a linked list of traceback frames and two chaining slots for context and cause.
A float is 24 bytes holding one IEEE-754 double. Arithmetic converts both sides to double and boxes the result, and repr always uses 17 significant digits with a trailing .0.