Skip to content

Core Python — Advanced (50+ Coding Exercises)

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