1个回答
展开全部
文件这样子:
代码:
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)
运行结果:
代码:
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)
运行结果:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询