Re: Sorting an Edge List
I found my old bubble sort solution: def esort(edges): while 1: swaps = 0 for j in range(len(edges)-2): if edges[j][1] != edges[j+1][0]: edges[j+1],edges[j+2] = edges[j+2],edges[j+1] # swap
Sorting an Edge List
I need to sort this list: [('A','Y'), ('J','A'), ('Y','J')] like this: [('A','Y'), ('Y','J'), ('J','A')]. Note how the Ys and Js are together. All I need is for the second element of one tuple to equal the first element of the next tuple. Another valid solution is [('J','A'), ('A','Y'), ('Y','J'