Plik tekstowy sortuj według pierwszego elementu w każdym wierszu
fn = 'filename.txt'
sorted_fn = 'sorted_filename.txt'
with open(fn,'r') as first_file:
rows = first_file.readlines()
sorted_rows = sorted(rows, key=lambda x: int(x.split()[0]), reverse=False)
with open(sorted_fn,'w') as second_file:
for row in sorted_rows:
second_file.write(row)
Combative Cormorant