Files
awesome-python/website/data/category_intros/algorithms-and-design-patterns.md
Vinta ChenandClaude 6956b226ac docs: rewrite Algorithms and Design Patterns category intro
The old intro recommended transitions, which the 2026-10-02 audit removed from the README section.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-10-02 13:53:21 +08:00

3.4 KiB

If a Python algorithms library has to run in production, Sorted Containers gives you sorted lists, dicts, and sets. To learn, read The Algorithms - Python.

How to choose:

  • Lists, dicts, and sets that stay sorted as you add and remove: Sorted Containers
  • Small, typed implementations you can install and read: algorithms
  • Algorithm code to study, browsed by topic: The Algorithms - Python
  • How classic design patterns look in Python, and which ones to skip: python-patterns
  • Workflows as states and transitions, up to full statecharts: python-statemachine

Python's standard library is great until you need a sorted collections type, and Sorted Containers fills that gap in pure Python, as fast as C extensions. SortedList keeps its values in order as you add() them, SortedDict is a dict that keeps a sorted list of its keys, and SortedSet does the same for a set.

algorithms collects minimal, clean, and well-documented implementations of data structures and algorithms. Each file stands alone, with docstrings, type hints, and complexity notes, and its README says they're designed to be read and learned from. Install it with pip install algorithms, then import an implementation by topic, like a sort or a graph search.

The Algorithms - Python implements algorithms for education, and its README says they may be less efficient than the standard library's own: read them to learn, not to ship. Start from its directory, which sorts them by topic. Its contributing guide asks each algorithm to carry type hints and doctests that test both valid and erroneous input, so the doctests show you how it behaves.

python-patterns is a collection of design patterns and idioms in Python, one file per pattern, grouped as creational, structural, behavioral, and more. Its README asks you to pay more attention to why you choose a pattern than to how you implement it. It also lists the patterns not recommended in Python: skip a Singleton class, since modules are already singletons, and prefer composition and delegation over deep inheritance.

python-statemachine builds flat state machines or full statecharts with compound states, parallel regions, and history, in sync and async code. Declare states as class attributes and transitions with state.to(target), and the events are the names you assign them to.

Before you hand-write python-patterns' State pattern for a real workflow, read python-statemachine's guide for coming from the State pattern. The whole workflow sits in one class body, and unreachable states fail when the class is defined, not at runtime. For more places to learn and practice algorithms, see awesome-algorithms.