I have a handful of different dates and times, represented as a handful of datetime objects in a list.
from datetime import datetime
arr = [datetime(2023, 9, 1, hour=4, minute=3),
datetime(2023, 9, 1, hour=2, minute=15),
datetime(2023, 9, 1, hour=6, minute=45),
# trimmed for brevity
]
If I wanted to see if two datetime objects fell within 24-hours of each other, that isn't terribly hard to do. Except, I'm trying to see if, given a list of datetime objects, at least n of them can be contained within a 24-hour time span.
For a real-world use case of this, those timestamps might represent sign-ins on a user account, and if a user attempts to log in too n times in 15 minutes, I might choose to take some action based on that*.
How can this be done in Python?
*Don't worry, I'm not actually trying to DIY authentication - that is purely an example.