我刚刚开始学习Python,如果有人愿意帮忙,我需要一些帮助、技巧或解决方案。你知道吗
我有一个这样的文件:
2 C00000002 score: -48.649 nathvy = 49 nconfs = 3878
3 C00000001 score: -44.988 nathvy = 41 nconfs = 1988
4 C00000002 score: -42.674 nathvy = 49 nconfs = 6740
5 C00000002 score: -42.453 nathvy = 49 nconfs = 4553
6 C00000002 score: -41.829 nathvy = 49 nconfs = 7559
7 C00000002 score: -41.156 nathvy = 49 nconfs = 2251
8 C00000002 score: -39.520 nathvy = 49 nconfs = 3129
9 C00000004 score: -38.928 nathvy = 24 nconfs = 150
10 C00000002 score: -38.454 nathvy = 49 nconfs = 9473
11 C00000004 score: -37.704 nathvy = 24 nconfs = 156
12 C00000001 score: -37.558 nathvy = 41 nconfs = 51
我的第二列是一些没有在这里排序的id,其中一些是重复的,例如(C00000001
)。它们都有一个不同的编号,后跟score:
(编号通常以-
开头)。你知道吗
我想做的是:
1) 读取第二列(未排序的ID),并始终选择出现的第一列。所以在C00000001
的情况下,它会用score : -44.988
选择on。你知道吗
2)现在当我有唯一的值时,我想根据score:
之后的数字对它们进行排序,这意味着最负的数字在第一个位置,而最正的数字在最后一个位置。你知道吗
这是一种可能性:
元组列表可以用于第一部分,但速度较慢。你知道吗
您可以使用简单的python实现这一点。Python列表内置了排序方法
嗨,这里有一个可能的解决方案
相关问题 更多 >
编程相关推荐