List of tuples

CHRIS unk at unk.ororr
Sat Aug 12 07:21:35 EDT 2000


lets say there's a list of tupples:

x = [('foo', 234, 32), ('bar', 213, 123)];

If I want to sort the list by the first element of the tuple should I
make a custom compare funciton:
def statcmp(t1, t2):
  if t1[0] < t2[0]:
    return 1;
  elif t1[0] == t2[0]:
    return 0;
  else:
    return -1;

x.sort(statcmp);

Or just sort:
x.sort();


Thanks.




More information about the Python-list mailing list