def variables_and_orphans(i, o):
 def expand(r):
  if (r.owner and (r not in i)):
   l = (list(r.owner.inputs) + list(r.owner.outputs))
   l.reverse()
   return l
 variables = stack_search(deque(o), expand, 'dfs')
 orphans = [r for r in variables if ((r.owner is None) and (r not in i))]
 return (variables, orphans)

def variables_and_orphans ( i , o ) : def expand ( r ) : if ( r . owner and ( r not in i ) ) : l = ( list ( r . owner . inputs ) + list ( r . owner . outputs ) ) l . reverse ( ) return l variables = stack_search ( deque ( o ) , expand , 'dfs' ) orphans = [ r for r in variables if ( ( r . owner is None ) and ( r not in i ) ) ] return ( variables , orphans )
extract list of variables between i and o nodes via dfs traversal and chooses the orphans among them parameters i : list input variables .