码迷,mamicode.com
首页 > 编程语言 > 详细

坐标点排序

时间:2018-03-05 15:32:20      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:lam   __str__   for   ted   sel   str   bsp   gpo   form   

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

坐标点排序

标签:lam   __str__   for   ted   sel   str   bsp   gpo   form   

原文地址:https://www.cnblogs.com/ydf0509/p/8508898.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!