Code Explainers
Python code explainers
python
import re from datetime import datetime from dataclasses import dataclass
Parsing access logs with named regex groups
regex
named-groups
dataclasses
Intermediate
6 steps
python
import gzip from pathlib import Path from typing import Iterator
Streaming TSV records with Python generators
generators
lazy-evaluation
file-io
Intermediate
5 steps
python
import hashlib import hmac import os
Verifying signed payment webhooks in Flask
hmac
webhooks
signature verification
Intermediate
7 steps
python
from flask import Blueprint, render_template, request, abort from sqlalchemy import select from .models import Article
Paginating articles in a Flask Blueprint
pagination
blueprints
input-validation
Intermediate
6 steps
python
from fastapi import APIRouter, Depends, Query from pydantic import BaseModel from sqlalchemy import func, select from sqlalchemy.ext.asyncio import AsyncSession
How a paginated list endpoint works in FastAPI
pagination
dependency-injection
async-orm
Intermediate
8 steps
python
from fastapi import FastAPI, Request, status from fastapi.responses import JSONResponse app = FastAPI()
Custom exception handlers in FastAPI
exception handling
error responses
separation of concerns
Intermediate
7 steps
python
class FileManager: """A context manager that safely opens and closes a file.""" def __init__(self, path, mode="r"):
Writing context managers in Python
context-managers
resource-management
exception-handling
Intermediate
6 steps
python
from collections import deque def bfs(graph, start):
Breadth-first search and shortest paths in Python
graph-traversal
bfs
queue
Intermediate
9 steps
python
class Typed: """A data descriptor that enforces a type and optional validation.""" def __init__(self, expected_type, validator=None):
Building a typed descriptor in Python
descriptors
validation
metaprogramming
Advanced
8 steps
python
from collections import Counter def word_frequencies(text):
Counting things with collections.Counter
counting
multiset
data-structures
Beginner
8 steps
python
def two_sum_sorted(numbers, target): """Find indices of two values that sum to target in a sorted array.""" left, right = 0, len(numbers) - 1 while left < right:
Two-pointer search on sorted arrays
two-pointers
arrays
sorting
Intermediate
9 steps