code: def topsort(graph):
      if len(graph) == 0:
          return []
      inedge_count = {
          k: len(v.inputs) + len(v.control_inputs)
          for k, v in graph.items()
      }
      ret = []
      curboundary = [k for k, v in inedge_count.items() if v == 0]
      nextboundary = []
      if len(curboundary) == 0:
          raise ValueError("Graph is not a DAG!")
  
      while len(curboundary) > 0:
          ret.extend(curboundary)
          for b in curboundary:
              for o in graph[b].outputs + graph[b].control_outputs:
                  inedge_count[o] -= 1
                  if inedge_count[o] == 0:
                      nextboundary.append(o)
          curboundary = nextboundary
          nextboundary = []
      if len(ret) != len(graph):
          raise ValueError("Graph is not a DAG!")
      return ret
  
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import six
label_desc: Use image node_id 20 for calling a global function with example usage: topsort(graph) and returns: ret, list