无题
import sys m = {} keys = [] ifile = open(sys.argv[1], 'r') ofile = open(sys.argv[2], 'w') while True: line = ifile.readline() if len(line) == 0: break line.strip() tmp = line.split(' ') if not m.has_key(tmp[1]): m[tmp[1]] = [] m[tmp[1]].append(tmp[2]) if keys.count(tmp[1]) == 0: keys.append(tmp[1]) keys.sort() for key in keys: ofile.write(key) ofile.write("\n"); m[key].sort() for ele in m[key]: ofile.write(ele) ofile.write("\n"); ifile.close() ofile.close()