我试图找出一种简单的方法来使用 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
任何帮助将不胜感激!!