Core Python — Advanced (50+ Coding Exercises)
- Implement an LRU cache class with
get/putin O(1). - Implement a TTL cache class with
get/putand background cleanup thread. - Implement a thread-safe counter with
increment/getand benchmark it with multiple threads. - Implement a thread pool executor wrapper that supports task cancellation and timeouts.
- Implement a process pool solution to parallelize CPU-bound image-like work (simulate with heavy math).
- Implement a producer/consumer pipeline with
queue.Queueand sentinel shutdown. - Implement a bounded concurrency runner for coroutines (limit N at a time) using
asyncio.Semaphore. - Implement an async function that fetches many URLs concurrently (use
aiohttp/httpxstructure, stub network if needed). - Implement
async_retrydecorator with exponential backoff and jitter. - Implement an async rate limiter (token bucket or leaky bucket).
- Implement a circuit breaker class (
closed/open/half-open) with failure thresholds. - Implement structured logging helper that injects a correlation ID into all log records.
- Implement correlation ID propagation using
contextvarsacross async tasks. - Implement a simple event bus supporting sync handlers and async handlers.
- Implement plugin loading from a
plugins/folder (dynamic imports) with a common interface. - Implement a configuration loader with precedence: defaults < file < env < CLI args.
- Implement a mini dependency injection container (register/resolve singletons and factories).
- Implement a descriptor
PositiveIntthat validates assigned values are positive integers. - Implement a
@cached_property-like decorator (thread-safe optional). - Implement a custom metaclass that auto-registers subclasses in a registry.
- Implement
__getattr__-based lazy loading of a resource (e.g., load JSON on first access). - Implement a robust file lock context manager (cross-platform best-effort using
fcntl/msvcrtfallback). - Implement a binary file format: header + records, plus reader/writer.
- Implement a streaming parser that reads records from a binary file without loading all.
- Implement a small profiler wrapper around
cProfilethat outputs top functions. - Implement a memory usage sampler (periodic
tracemallocsnapshot diff). - Implement a hot-reloader that watches a file mtime and reloads a module.
- Implement an expression tokenizer for numbers/operators/parentheses.
- Implement a Pratt parser or shunting-yard parser for arithmetic expressions.
- Implement an AST evaluator supporting variables and assignments.
- Implement a simple template renderer with
{{var}}placeholders (safe escaping optional). - Implement a minimal cron-like scheduler that runs jobs at intervals (seconds-based is fine).
- Implement a job scheduler that persists job state to a JSON file.
- Implement a resilient retry queue that stores failed tasks for later retry.
- Implement a bulkhead pattern limiting concurrent calls per dependency.
- Implement idempotency key storage for API-like operations (in-memory + TTL).
- Implement a safe pickle alternative using JSON and custom encoders for dataclasses.
- Implement a
Protocolinterface for storage and provide in-memory + file-based implementations. - Implement a typed
Result[T, E]class and use it in a small workflow. - Implement a concurrent map function that preserves input order.
- Implement a pipeline that fans out work and gathers results with timeouts.
- Implement an async queue worker system with graceful shutdown and drain.
- Implement a resilient HTTP client wrapper (timeouts, retries, circuit breaker hooks).
- Implement an audit logger that writes JSON lines and rotates by size.
- Implement log rotation by day (create new file when date changes).
- Implement a large-file tailer that follows appended lines (like
tail -f). - Implement an incremental CSV exporter that streams rows to disk.
- Implement a deduplicating message queue using hashing and TTL.
- Implement a minimal actor model: mailbox per actor, message handlers, stop signals.
- Implement a benchmark harness to compare two functions over multiple iterations.
- Implement a trie data structure with insert/search/prefix search.
- Implement a Bloom filter with configurable false positive rate (basic version).