def order_workflow_steps(steps):
 position_data_available = True
 for step in steps:
  if ((not step.position) or ('left' not in step.position) or ('top' not in step.position)):
   position_data_available = False
 if position_data_available:
  steps.sort(key=(lambda _: math.sqrt(((_.position['left'] ** 2) + (_.position['top'] ** 2)))))
 try:
  edges = edgelist_for_workflow_steps(steps)
  node_order = topsort(edges)
  return [steps[i] for i in node_order]
 except CycleError:
  return None

def order_workflow_steps ( steps ) : position_data_available = True for step in steps : if ( ( not step . position ) or ( 'left' not in step . position ) or ( 'top' not in step . position ) ) : position_data_available = False if position_data_available : steps . sort ( key = ( lambda _ : math . sqrt ( ( ( _ . position [ 'left' ] ** 2 ) + ( _ . position [ 'top' ] ** 2 ) ) ) ) ) try : edges = edgelist_for_workflow_steps ( steps ) node_order = topsort ( edges ) return [ steps [ i ] for i in node_order ] except CycleError : return None
perform topological sort of the steps .