【发布时间】:2023-07-02 12:13:02
【问题描述】:
我有一个类对象 my_rectangle 的列表:
class my_rectangle:
def __init__(self,text,x_start,y_start,x_end,y_end):
self.text=text
self.x_start=x_start
self.y_start=y_start
self.x_end=x_end
self.y_end=y_end
self.x_centroid=(self.x_start+self.x_end)/2
self.y_centroid=(self.y_start+self.y_end)/2
使用给出质心坐标的类属性(x_centroid 和y_centroid),我想排序这个列表,使用从左到右然后从上到下的顺序(普通英文阅读顺序)?
说我有:
A=my_rectangle('Hi,',1,3,2,4)
B=my_rectangle('Im',3,3,3,4)
C=my_rectangle('New',1,1,2,2)
my_list=[C,B,A]
我想订购它来获得:
my_sorted_list=[A,B,C]
这是文本的表示:
""" Hi, I'm
New
"""
【问题讨论】: