Free lab Real Python 3. Zero installs. Your code stays in this browser. Open the playground

API Rate Limiter

Hard · 90 XP

Implement allow(timestamps, window, limit): given sorted request timestamps (seconds), return how many requests would be rejected if only limit requests are allowed per rolling window seconds. Process requests in order; a request is rejected if the number of accepted requests in the last window seconds (inclusive) has reached limit. Print the result for the starter data.

Target output
4
Blank · autosaved
PYapi-rate-limiter.py
Run your code to check it…
Your next ten minutes

Write Python that does something useful.

Start free. No install, no card, no passive video marathon.

Start learning free → Explore the path