背包排序(初步方案)

xiaoxiao2026-05-21  12

>>> 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)

 

转载请注明原文地址: https://www.6miu.com/read-5049108.html

最新回复(0)