def interleave_entries(queue_entries, special_tasks):
 _compute_next_job_for_tasks(queue_entries, special_tasks)
 interleaved_entries = []
 for task in special_tasks:
  if (task.next_job_id is not None):
   break
  interleaved_entries.append(_special_task_to_dict(task))
 special_task_index = len(interleaved_entries)
 for queue_entry in queue_entries:
  interleaved_entries.append(_queue_entry_to_dict(queue_entry))
  for task in special_tasks[special_task_index:]:
   if (task.next_job_id < queue_entry.job.id):
    break
   interleaved_entries.append(_special_task_to_dict(task))
   special_task_index += 1
 return interleaved_entries

def interleave_entries ( queue_entries , special_tasks ) : _compute_next_job_for_tasks ( queue_entries , special_tasks ) interleaved_entries = [ ] for task in special_tasks : if ( task . next_job_id is not None ) : break interleaved_entries . append ( _special_task_to_dict ( task ) ) special_task_index = len ( interleaved_entries ) for queue_entry in queue_entries : interleaved_entries . append ( _queue_entry_to_dict ( queue_entry ) ) for task in special_tasks [ special_task_index : ] : if ( task . next_job_id < queue_entry . job . id ) : break interleaved_entries . append ( _special_task_to_dict ( task ) ) special_task_index += 1 return interleaved_entries
both lists should be ordered by descending id .