0
我想要找出一个简单的方法来从使用python的文件升序排序数字。如何在python文件中按升序对数字进行排序(通过插入排序)
这就是我到目前为止 - 但它似乎并没有工作!
input_file = open('C:\\Users|\Desktop\\data.txt')
for line in input_file:
print line
print('Before: ', input_file)
insertion_sort(input_file)
print('After : ', input_file)
def insertion_sort(items):
""" Implementation of insertion sort """
for i in range(1, len(items)):
j = i
while j > 0 and items[j] < items[j-1]:
items[j], items[j-1] = items[j-1], items[j]
j -= 1
任何帮助将不胜感激!!
究竟不起作用?我已经可以看到两个会导致脚本无法工作的错误 –