I have a list of integer tuples like this:
L=[(1,2),(7,6),(2,3),(8,5),(3,8),(5,7)]
Each pair defines an edge between two vertices and I want to find the vertex connectivity.
There are no loops, the tuples always uniquely link up like dominoes so in this case the sorted list should look like:
L_sorted=[(1,2),(2,3),(3,8),(8,5),(5,7),(7,6)]
Or alternatively
L_sorted=[1,2,3,8,5,7,6]
Is there an efficient way to do sorting like this in Python using predefined methods?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…