John, there's an error in my program, I forgot that list.sort() method doesn't return the list (it sorts in place). So it should look like: #!/usr/bin/python def sortit(fname): fo = open(fname) linedict = {} for line in fo: key = line[:3] linedict[key] = line sortedlines = [] keys = linedict.keys() keys.sort() for key in keys: sortedlines.append(linedict[key]) return sortedlines if __name__ == '__main__': sortit('testfile.txt') MRAB's solution is obviously better, provided you know about Python's lambda. Regards, mk
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4