文件這樣子:
代碼:
fl = open('luciatest1.txt')
l = []
sortedl = []
for lines in fl.readlines():
lines = lines.replace("\n", "")
l.append(lines)
print('\n', 'the original file is:', l)
sortedl = sorted(l)
print('\n', 'the sorted file is:', sortedl)
運行結果: