I have lists of exactly two previous and next items.
[['Robert','Christopher'],['John','Eric'],['Mark','John'],['Mickael','Robert']]
For the first list, 'Robert' is previous and 'Christopher' next.
I would like to merge them having the lowest previous and the highest next by keeping the continuity of the final lists. Result can be:
[['Mickael','Christopher'],['Mark','Eric']]
or
[['Mark','Eric'],['Mickael','Christopher']]
The result is two lists because there are no continuity between these two lists. previous and next cannot be sorted (For example 'Mickael' is before 'Christopher'). There are no loops and no repeated elements (i.e. 'Robert' is always before 'Christopher', 'John' is always before 'Eric'...) so this is a topological graph
Is it possible easily in python?