我的标准输出如下:
seventy-five 0.050
states 0.719
drainage-basin 0.037
scotland 0.037
reading 0.123
thirty-eight 0.000
almost 0.037
rhine 0.000
proper 0.037
contrary 0.087
有什么简单的方法可以根据后面的浮点数按降序排列长的标准输出列表,并保持标准输出格式,而不是将其转换为列表和排序?很抱歉问这个愚蠢的问题,因为我是python的初学者
Tags:
用列表排序似乎很自然。您可以按每行(
data.split('\n')
)末尾的浮点值对行(float(line.split()[-1]
)排序,并使用reverse
关键字获得降序如果您不喜欢列表,可以使用命令行工具,如sort
相关问题 更多 >
编程相关推荐