lst = []
withopen('test.txt' , 'r') as f1:
for onf in f1.readlines():
lst.append(int(onf))
print(' '.join([str(i) for i insorted(lst,reverse = True)]))
weixin_39851048的博客使用现有代码并解决如何将列表转换为整数的特定问题:使用list comprehension以下示例,可以遍历每一行并将字符串转换为int:给出:line =['3', '4', '1\r\n']然后:int_list = [int(i) for i in line]将生成一个...
燕碎的博客I have a file format like this:9 8 13 4 1......Now, I want to get each line as three integers.When I usedfor line in f.readlines():print line.split(" ")The script printed this:['9', '8', '1\r\n']['3',...
A格调的博客I have a text file(data.txt) containing names and scores 1:1 i.e.:Mike = 1\n John = 2\n Cam = 3\nI want to sort the integers along with the corresponding name in ascending and descending order.with op...
一JJL的博客with open('data.txt','r') as fp: data=fp.readlines() print(data) data=[int(line.strip()) for line in data] data.sort() data=[str(i)+'\n' for i in data] ...运行后: 自动生成了一个data_asc.txt文件