[Tutor] string to list
Owain Clarke
simbobo at cooptel.net
Wed Feb 10 17:57:01 CET 2010
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
More information about the Tutor
mailing list