>>> def sortFunc(x,y):
>>> if x>y:
>>> return 1
>>> elif x==y:
>>> return 0
>>> else x<y:
>>> return -1
>>> list = [5, 1, 3, 2, 4]
>>> list.sort(sortFunc)
[1, 2, 3, 4, 5]
>>> list = [5, 1, 3, 2, 4]
>>> list.sort(lambda x,y : x-y)
[1, 2, 3, 4, 5]
#效果相同,但方法不同.
>>> list=[5, 1, 3, 2, 4]
>>> list.sort(lambda x,y : id(x) - id(y) )
>>> list
[5, 4, 3, 2, 1]
# ----背包系统----
# 正续排列
tempList = [object, object, object, object, object]
tempList.sort(lambda x,y : x.type - y.type)
# BigItem
BagItem.reBag(tempList)
# 倒序排列
tempList = [object, object, object, object, object]
tempList.sort(lambda x,y : y.type - x.type)
# BigItem
BigItem.reBag(tempList)