# coding: utf8
class A():
def __init__(self):
self.click = 0
a = A()
a.click = 4
a.test = 'I am a'
b = A()
b.click = 1
b.test = 'I am b'
c = A()
c.click = 2
c.test = 'I am c'
for i in sorted([a, b, c], key=lambda x: x.click, reverse=True):
print i.test
# 输出(根据click的值从小到大输出test属性)
I am b
I am c
I am a
这样吗?
写了个例子:
是这个意思吗