【发布时间】:2011-12-17 23:35:51
【问题描述】:
我有一堂课:
class Prediction():
def __init__(self, l):
self.start = l[0]
self.end = l[1]
self.score = l[2]
还有一个列表,其中每个元素都是一个Prediction。它被恰当地命名为predictions。
我想按Prediction 类的start 属性对predictions 进行排序。
类似这样的:
predictions_start_order = sorted(predictions, key=start)
这不起作用。我错过了什么?
【问题讨论】:
标签: python class list user-defined-types