nodes: 0, module; 1, function_definition; 2, function_name:find_order; 3, parameters; 4, block; 5, identifier:graph; 6, expression_statement; 7, while_statement; 8, string; 9, identifier:graph; 10, comment:# Find all items without a parent; 11, block; 12, string_content:Do a topological sort on the dependency graph dict.; 13, expression_statement; 14, if_statement; 15, comment:# If there is more than one, sort them for predictable order; 16, expression_statement; 17, for_statement; 18, assignment; 19, not_operator; 20, block; 21, call; 22, identifier:result; 23, identifier:leftmost; 24, comment:# Yield and remove them from the graph; 25, block; 26, identifier:leftmost; 27, list_comprehension; 28, identifier:leftmost; 29, raise_statement; 30, attribute; 31, argument_list; 32, expression_statement; 33, expression_statement; 34, for_statement; 35, identifier:l; 36, for_in_clause; 37, if_clause; 38, call; 39, identifier:leftmost; 40, identifier:sort; 41, yield; 42, call; 43, identifier:bset; 44, call; 45, block; 46, pattern_list; 47, call; 48, not_operator; 49, identifier:ValueError; 50, argument_list; 51, identifier:result; 52, attribute; 53, argument_list; 54, attribute; 55, argument_list; 56, expression_statement; 57, identifier:l; 58, identifier:s; 59, attribute; 60, argument_list; 61, identifier:s; 62, binary_operator:'Dependency cycle detected! %s' % graph; 63, identifier:graph; 64, identifier:pop; 65, identifier:result; 66, identifier:graph; 67, identifier:values; 68, call; 69, identifier:graph; 70, identifier:items; 71, string; 72, identifier:graph; 73, attribute; 74, argument_list; 75, string_content:Dependency cycle detected! %s; 76, identifier:bset; 77, identifier:discard; 78, identifier:result
code: def find_order(graph):
      '''
      Do a topological sort on the dependency graph dict.
      '''
      while graph:
          # Find all items without a parent
          leftmost = [l for l, s in graph.items() if not s]
          if not leftmost:
              raise ValueError('Dependency cycle detected! %s' % graph)
          # If there is more than one, sort them for predictable order
          leftmost.sort()
          for result in leftmost:
              # Yield and remove them from the graph
              yield result
              graph.pop(result)
              for bset in graph.values():
                  bset.discard(result)