topological sort in python