python - 获取对象列表中属性值最大的对象列表

标签 python list attributes max

previous questions 略有不同。我在这里找到了: front_Ar 是具有 score 属性的对象列表。

我正在尝试获取得分最高的所有对象的列表。 我已经尝试过:

maxind = []
maxInd.append(max(front_Ar, key=attrgetter('score')))

仅存储一个对象(大概是它找到的第一个对象)。 知道如何做到这一点吗?

最佳答案

首先找到最高分数,然后根据该分数过滤列表:

max_score = max(front_Ar, key=attrgetter('score')).score
max_ind = [obj for obj in front_Ar if obj.score == max_score]

关于python - 获取对象列表中属性值最大的对象列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42169655/

相关文章:

python - python中的链式调用父初始化器

python - 如何突出显示数据帧的两个不同列中的唯一数据值?

asp.net-mvc - 在方法中获取 ActionFilterAttribute 的实例

Magento - 属性 "input-type"复选框

python - 运行多个 python

python - 稀疏数据帧上的 Pandas.concat ……一个谜?

python - 使用python从网站下载csv文件

c# - 来自字典 C# 的数组

list - Oracle Apex - 选择列表填充文本字段

.net - 有没有办法将属性放在匿名类型属性上?