# Python's Built-in Operations: A Big-O Cheat Sheet

Original title: Time complexity of operations on Python's built-in types

> Hacker News story 49435595 · language: en · submitted 2026-08-25
> Web version: https://zeli.app/story/49435595
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 107 · by [theanonymousone](<https://news.ycombinator.com/user?id=theanonymousone>) · 💬 42
[original](<https://docs.python.org/3.16/library/time-complexity.html>) · [HN discussion](<https://news.ycombinator.com/item?id=49435595>)

## Summary

The official Python documentation details the time complexity of operations on built-in types, from lists and dicts to memoryviews and ranges. It covers average-case costs, worst-case scenarios for hash collisions, and notes on implementation specifics like CPython's list resizing and frozendict's immutability.

## Key quote

> If you need to add or remove at both ends, consider using a collections.deque instead.

## HN discussion (42 comments)

### [alexpotato](<https://news.ycombinator.com/item?id=49489092>)

> Dave Beazley has a great talk about using Python built ins [0] for data analysis and other quick operations.
>
> As a meta note, I've used many of these builtins over the years but, due to LLMs, have been using them less and less. Re-watching the video almost felt like watching bushcrafters make a chair using just a knife and saw...
>
> 0 - https://www.youtube.com/watch?v=lyDLAutA88s

### [Retr0id](<https://news.ycombinator.com/item?id=49491517>)

> Excellent. Previously this was only documented semi-unofficially on the wiki here: https://wiki.python.org/moin/TimeComplexity

### [StellarScience](<https://news.ycombinator.com/item?id=49490819>)

> Python is famously built around hash tables. So much so that several versions ago they made an improvement to the hash table implementation, and the entire language became several percent faster.
>
> However, I'm surprised to see no data structures at all with O(log(N)) complexity. Surely there are some use cases for which that's desirable?

### [mwkaufma](<https://news.ycombinator.com/item?id=49491836>)

> Isn't O(n - k) or O(len(l1) + len(l2)) just O(n)? Instead of blurring the line between complexity-analysis and cycle-counting, just print both the complexity and the est proportional cycle-count as separate measures.

### [wodenokoto](<https://news.ycombinator.com/item?id=49488775>)

> Why are `min(r)` and `max(r)` for range objects o(n) ?
>
> I thought min and max where constants stored in the object. Basically you are just asking for one of the parameters it was created with.

---

## Cite

- Page: https://zeli.app/story/49435595
- Date: 2026-08-25
- Source: docs.python.org (https://docs.python.org/3.16/library/time-complexity.html)
- Hacker News: https://news.ycombinator.com/item?id=49435595

## Other languages

- zh: https://zeli.app/zh/story/49435595 · markdown: https://zeli.app/zh/story/49435595.md
- ja: https://zeli.app/ja/story/49435595 · markdown: https://zeli.app/ja/story/49435595.md
- ko: https://zeli.app/ko/story/49435595 · markdown: https://zeli.app/ko/story/49435595.md
- de: https://zeli.app/de/story/49435595 · markdown: https://zeli.app/de/story/49435595.md
- es: https://zeli.app/es/story/49435595 · markdown: https://zeli.app/es/story/49435595.md
- ru: https://zeli.app/ru/story/49435595 · markdown: https://zeli.app/ru/story/49435595.md
