current position:Home>Text file problem output new file

Text file problem output new file

2022-02-02 20:58:40 CSDN Q & A

Python It is known that several comma separated integers are stored in a text file , Output all numbers in descending order and write them to a new file . How do the great gods write code , Thank you

Refer to the answer 1:
f = open("newFile.txt",'w')with open("filename", 'r' ) as FA:    for line in FA:        line = line.strip().split(',')        sortLine = line.sort(reverse = True)        f.write(",".join(i for i in sortLine)+'\n')f.close()

Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.

Random recommended