list vs tuple vs set: What I Found After 100K Iterations
I ran 100,000 read/write operations on Python's three core collection types. tuple beat list by 12% in lookups. set crushed both by 99.8% for membership checks. But here's what caught me off guard: list writes were slower than tuple creation for batches under 1000 items.
Most Python guides tell you "tuples are faster because they're immutable." That's... partially true. The real story involves hash tables, memory allocation strategies, and one gotcha with in operators that I wish I'd known three years ago.
Let me show you the actual numbers.
The Benchmark Setup
I tested on Python 3.11.7 (the version where dictionary ordering became a language guarantee, not just CPython quirk). MacBook M1 Pro, 16GB RAM. Each operation repeated 100K times using timeit with 3-second warmup.
Three scenarios:
- Creation: Building a collection from scratch with 1K integers
- Read: Random index/membership access across the collection
- Write: Appending/adding 100 new elements
Continue reading the full article on TildAlice

Top comments (0)