def topsort(graph):
count = defaultdict(int)<EOL>for feature, node in graph.items():<EOL><INDENT>for target in node:<EOL><INDENT>count[target] += <NUM_LIT:1><EOL><DEDENT><DEDENT>free_nodes = list(filter(lambda x: count[x] == <NUM_LIT:0>, graph))<EOL>result = []<EOL>while free_nodes:<EOL><INDENT>node = free_nodes.pop()<EOL>result.append(node)<EOL>for target in graph[node]:<EOL><INDENT>count[target] -= <NUM_LIT:1><EOL>if count[target] == <NUM_LIT:0>:<EOL><INDENT>free_nodes.append(target)<EOL><DEDENT><DEDENT><DEDENT>return result<EOL>
For the given graph, returns a list of nodes in topological order
In py3 the behaviour of this function differs from py2,
the resulting order will change with every execution in py3
while in py2 the order stays the same
:param graph:
:return: