Hi:
I'm trying to sort a list of tuples in a custom way:
For example:
lt = [(2,4), (4,5), (5,2)]
must be sorted:
lt = [(5,2), (2,4), (4,5)]
Rules:
* b tuple is greater than a tuple if a[1] == b[0]
* a tuple is greater than b tuple if a[0] == b[1]
I've implemented a cmp function like this:
def tcmp(a, b):
if a[1] == b[0]:
return -1
elif a[0] == b[1]:
return 1
else:
return 0
but sorting the list:
lt.sort(tcmp)
lt show me:
lt = [(2, 4), (4, 5), (5, 2)]
What am I doing wrong?