With thanks to all who made suggestions, this was what I settled on
f = open('testfile')
#(testfile consisting of 2 columns of data, as per Kent's suggestion)
data = []
for line in f:
line_data = [int(x) for x in line.split()]
data.append(line_data)
data.sort(key=lambda x:x[0])
print "sort by first key:", data
data.sort(key=lambda x:x[1])
print "sort by second key:", data
I would love a really clear explanation of lambda!
Owain
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor