Generators, Iterators & Time Complexity

Unit 5: OOP, Iterators & Complexity · 8 min read

The iterator protocol (__iter__/__next__), streaming O(1)-memory pipelines with yield, and real Big-O costs of Python containers.

Key Concepts

  • Single-pass exhaustion of iterators and generators
  • yield vs yield from delegation
  • O(1) deque.popleft() vs O(n) list.pop(0)
  • Choosing list, deque, set, dict, or heapq by workload

Official Python Docs

Back to Python Notes Hub