你可以使用以下代码来实现这个功能:

def sort_lines_by_last_number(file_path):
    # 读取文件内容
    with open(file_path, 'r') as file:
        lines = file.readlines()

    # 按最后的数字从大到小排序
    sorted_lines = sorted(lines, key=lambda line: int(line.strip().split()[-1]), reverse=True)

    # 打印排序结果
    for line in sorted_lines:
        print(line.strip())

# 示例用法
file_path = 'input.txt'  # 替换为你的输入文件路径
sort_lines_by_last_number(file_path)

这个脚本会按最后的数字从大到小排序输入文件中的每一行,并打印排序结果。你需要将file_path变量替换为你的输入文件路径。

写一个python脚本把一个输入的txt中每一行按最后的数字从大到小排序

原文地址: http://www.cveoy.top/t/topic/iYxS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录