+ -
当前位置:首页 → 问答吧 → [新手请教]关于python re.match的一个小问题,谢谢

[新手请教]关于python re.match的一个小问题,谢谢

时间:2011-08-21

来源:互联网

代码:
class Node:
   def __init__(self):
      self.x = 0
      self.y = 0
      self.z = 0
   
   def Scan(self):
      self.x, self.y, self.z = raw_input().split()
   
   def __lt__(self, oth):
      return self.x < oth.x and self.y < oth.y and self.z < oth.z

def comp(a, b):
   return a.x < b.x

n = int(raw_input())
a = [Node() for i in range(0, n + 1)]
for i in range(1, n + 1):
   a[i].Scan()

a.sort(comp)

for i in range(1, n + 1):
   print a[i].x, a[i].y, a[i].z


以上是部分代码
Node是我自己定义的一个类, 那个重载的小于号在后面要用,和排序无关
然后我想按Node的x关键字排序
但是这样写之后,对于a里面的数据没有变化, 还是乱序
求各位高手指教

作者: Vani^_^   发布时间: 2011-08-21

代码:
def comp(a, b):
   return a.x - b.x

作者: cuihao   发布时间: 2011-08-21