首页 > 代码库 > Python 多级排序
Python 多级排序
class C( object ): def __init__( self, x1, x2, x3 ): self.x1 = x1 self.x2 = x2 self.x3 = x3 def __cmp__( self, other ): if self.x1 < other.x1: return -1 elif self.x1 == other.x1: if self.x2 < other.x2: return -1 elif self.x2 == other.x2: if self.x3 < other.x3: return -1 elif self.x3 == other.x3: return 0 else: return 1 else: return 1 else: return 1 def __repr__( self ): return "({x1}, {x2}, {x3})".format( x1 = self.x1, x2 = self.x2, x3 = self.x3 ) import random r = random.randint li = [] for i in xrange( 15 ): li.append( C( r( 1, 10 ), r( 1, 10 ), r( 1, 10 ) ) ) for i in li: print i print li1 = sorted( li ) for i in li1: print i
Python 多级排序
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。