坐标点排序

# coding=utf-8


class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __str__(self):
        return '({}, {})'.format(self.x, self.y)

points = [Point(9, 2), Point(1,5), Point(2, 7), Point(3, 8), Point(2, 5)]

sorted_points = sorted(
        points,
        key = lambda point: (point.x,point.y))


print ('  '.join(map(str, sorted_points)))

 

 

(1, 5)  (2, 5)  (2, 7)  (3, 8)  (9, 2)

posted @ 2018-03-05 14:44  北风之神0509  阅读(458)  评论(0编辑  收藏  举报