def correlate_data(data, timestamps):
 timestamps = list(timestamps)
 data_by_frame = [[] for i in timestamps]
 frame_idx = 0
 data_index = 0
 data.sort(key=(lambda d: d['timestamp']))
 while True:
  try:
   datum = data[data_index]
   ts = ((timestamps[frame_idx] + timestamps[(frame_idx + 1)]) / 2.0)
  except IndexError:
   break
  if (datum['timestamp'] <= ts):
   datum['index'] = frame_idx
   data_by_frame[frame_idx].append(datum)
   data_index += 1
  else:
   frame_idx += 1
 return data_by_frame

def correlate_data ( data , timestamps ) : timestamps = list ( timestamps ) data_by_frame = [ [ ] for i in timestamps ] frame_idx = 0 data_index = 0 data . sort ( key = ( lambda d : d [ 'timestamp' ] ) ) while True : try : datum = data [ data_index ] ts = ( ( timestamps [ frame_idx ] + timestamps [ ( frame_idx + 1 ) ] ) / 2.0 ) except IndexError : break if ( datum [ 'timestamp' ] <= ts ) : datum [ 'index' ] = frame_idx data_by_frame [ frame_idx ] . append ( datum ) data_index += 1 else : frame_idx += 1 return data_by_frame
data: list of data : each datum is a dict with at least: timestamp: float timestamps: timestamps list to correlate data to this takes a data list and a timestamps list and makes a new list with the length of the number of timestamps .