Talk presented at Python Asia (PyCon APAC) 2026.
All of us have wondered sometime, what really happens when a list is created, or compare dictionaries, or use objects as set keys in Python? This talk explores the inner workings of Python's core data types - lists, tuples, dicts, sets, and more - from the perspective of internal implementation, memory, mutability, method resolution and more.
Along the way, we look at practical examples of customizing these behaviors using special methods. Let's make an immutable list or a mutable tuple - we explore what's possible, what's dangerous, and what's just plain fun.
https://my.visme.co/view/nmngo6rz-python-asia-2026
| File | Topic |
|---|---|
demo1.py |
List basics - how len() and + map to dunder methods |
demo2.py |
Dict ordering - dict vs OrderedDict in modern Python |
demo3.py |
Hashable list - using a list as a dictionary key |
demo4.py |
Indexed set - adding __getitem__ to a set |
demo5.py |
Indexed set with slice support |
demo6.py |
TimeSeries - date-based __getitem__ indexing |
demo7.py |
OrderedSet - a set that preserves insertion order |
demo8.py |
Breaking frozen dataclass via object.__setattr__ |
demo9.py |
Mutable tuple - modifying a tuple in memory with ctypes |
demo10.py |
Generators and two-way communication with send() |
demo11.py |
Generator-based coroutines - producer-consumer pattern |
demo12.py |
Rolling average using generator send() |
Run any demo:
python demo1.py- Python 3.10+
- No external dependencies (only stdlib:
ctypes,collections,dataclasses,hashlib,datetime)
Note:
demo9.py(mutable tuple) is CPython-specific and handles the struct layout differences between Python <= 3.13 and Python 3.14+.
- Introduction (3 min) - Why look under the hood?
- Python Data Model in Action (10 min) - Dunder methods, hash contract, mutability
- The Hacks & Demos (14 min) - Hashable list, mutable tuple, indexed set, ordered set, date-indexed TimeSeries, frozen dataclass bypass, generator coroutines
- The Good, the Bad, and the Dangerous (2 min) - When these hacks help vs when they break things
- Wrap-up + Q&A (1 min)