def file_read(): result = [] with open("file.txt", "r", encoding="utf-8") as f: # 需保证python文件与访问文件 在一个文件夹中 while True: list1 = f.readline() if len(list1) == 0: break list2 = list1.split(",")[-1].strip() #以逗号为分隔符,将字符串分隔开 #[-1]为取最后一个数字 #strip()函数为消除个行列之间的空隙 result.append(list2) return result list3 = file_read() list3.sort() #对列表进行排序 print(list3)
读取文件中的数据,并对最后一列数字进行排序
最新推荐文章于 2024-07-31 14:30:10 发布