I have some interesting using cases in my Ruby code that I want to convert to Python. I think we can leverage in any lib, I mainly use pandas and numpy.
For instance, imagine that you have an array of timed events, these events have a timestamp and another properties (an object or a tuple).
I want a list/array of groups, where these groups are "contiguous" events, with a grace period of g
units (in this case, time units).
In my Ruby code I use something like this:
grouped_events = events.chunk_while do |previous_event, next_event|
next_event.timestamp <= previous_event.timestamp + grace_period
end
Since I'm not using only in timed events, but with anything that I can sort (so they're comparable somehow), I ask: there's a generic way, or a known lib that does this?