如何根据对象的属性对对象列表进行排序? - How to sort a list of objects based on an attribute of the objects?

问题:

I've got a list of Python objects that I'd like to sort by an attribute of the objects themselves. 我有一个Python对象列表,我想按对象自己的属性对其进行排序。 The list looks like: 该列表以下所示: ajax

>>> ut
[<Tag: 128>, <Tag: 2008>, <Tag: <>, <Tag: actionscript>, <Tag: addresses>,
 <Tag: aes>, <Tag: ajax> ...]

Each object has a count: 每一个对象都有一个计数: this

>>> ut[1].count
1L

I need to sort the list by number of counts descending. 我须要按递减计数对列表进行排序。 spa

I've seen several methods for this, but I'm looking for best practice in Python. 我已经看到了几种方法,可是我正在寻找Python的最佳实践。 .net


解决方案:

参考一: https://stackoom.com/question/1gwn/如何根据对象的属性对对象列表进行排序
参考二: https://oldbug.net/q/1gwn/How-to-sort-a-list-of-objects-based-on-an-attribute-of-the-objects
相关文章
相关标签/搜索