小编use*_*861的帖子

在具有类的列表上使用python Sorted函数

我目前正在尝试使用内置函数Sorted来对具有名为scores的类属性的列表进行排序.

这里排序的函数只与列表一起工作,它按升序正确地对分数进行排序.

Scores = [1,5,19,0,900,81,9000]


print(sorted(Scores))
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试将此函数应用于具有类属性的列表时,将返回错误:AttributeError:'list'对象没有属性'Score'

这是我的代码:

print(sorted(RecentScores.Score))
Run Code Online (Sandbox Code Playgroud)

任何帮助将非常感激.

下面是我的类初始化和列表RecentScores

class TRecentScore():
  def __init__(self):
    self.Name = ''
    self.Score = 0

RecentScores = [1,5,0]
Run Code Online (Sandbox Code Playgroud)

python sorting list

1
推荐指数
1
解决办法
68
查看次数

标签 统计

list ×1

python ×1

sorting ×1