Given lists: [1, 5, 6], [2, 3, 5, 6], [2, 5] etc. (not necessarily in any sorted order) such that if x precedes y in one list, then x precedes y in every list that have x and y, I want to find the list of all elements topologically sorted (so that x precedes y in this list if x precedes y in any other list.) There might be many solutions, in which case I want any of them.
What is the easiest way to implement this in Python.
Here is a slightly simpler version of @unutbu’s networkx solution: