Say I have a list of objects. Each of these has a string representing a date (parseable by dateutil). How can I go about grouping these in a list of lists, in which each sublist contains consecutive (within 5 minutes) objects? For example:
o1.time = "2016-03-01 23:25:00-08:00"
o2.time = "2016-03-01 23:30:00-08:00"
o3.time = "2016-03-01 23:35:00-08:00"
o4.time = "2016-03-02 12:35:00-08:00"
list1 = [o1, o2, o3, o4]
list2 = group_by_time(list1)
at which point list2 would be
[[o1,o2,o3],[o4]]
It seems like there should be a python solution using lambdas or itertools along with dateutil, but my google schools are failing me.
Thanks!