
Inside CPython Lists: Contiguous Memory, Fast Indexing, Resizing. A Mental Model for Interviews
In this article you’ll learn how CPython lists actually work under the hood: how a static array model explains fast indexing and “no holes” behavior why contiguity matters, and how indexing reduces to one computation what really happens when the list grows: allocate → copy → repoint how size vs capacity drives CPython’s over-allocation strategy why append() is amortized O(1), even though resizes are sometimes O(N) why insert() / delete-from-middle are O(N) due to shifting how the list is structured (metadata “head” + contiguous “body” of references) how to answer common list interview questions from first principles (not memorization) Before we start, one note: everything below began as a personal note. I wrote it while prepping for interviews. But the deeper I dug into CPython and the more I looked under Python’s hood, the clearer the big picture became. It’s like a puzzle: you don’t just assemble it you first have to dig up the pieces. I won’t drag out the intro. I just want to say t
Continue reading on Dev.to Python
Opens in a new tab



