I'm newbie both in the forum and in Python, I hope I'll do everything in the right way (tell me everything I'm doing wrong so I can improve it).
About my question: I've many class-object (is this the correct name?) in a list (this class-object are all the rectangle inside a matrix(=nested list)).
All of this rectangle has many attributes, some of these are: "X_SX", "Y_SX", "X_DX", "Y_DX" (they are the coordinates of left-up vertex ("X_SX", "Y_SX") and right-down vertex ("X_DX", "Y_DX") of the rectangle.
I've to find the min value of X_SX and Y_SX and the max value of X_DX and Y_SX. This is what I've done:
def find_box(rectangles):
x_sx = (min(getattr(rec, 'x_sx') for rec in rectangles))
y_sx = (min(getattr(rec, 'y_sx') for rec in rectangles))
x_dx = (max(getattr(rec, 'x_dx') for rec in rectangles))
y_dx = (max(getattr(rec, 'y_dx') for rec in rectangles))
It actually work but I was wondering if there is a way to do it in a better way and avoid to call the for-loop 4 times in the same list
NOTE: I'm not sure if I explain this badly but for a better comprehension this is the list "rectangles" where "Rectangle" is the Class I've definied:
[<__main__.Rettangolo object at 0x000001FAF3971C70>, <__main__.Rettangolo object at 0x000001FAF36E2B80>, <__main__.Rettangolo object at 0x000001FAF3971850>, <__main__.Rettangolo object at 0x000001FAF3B55A30>]
Thank you for your time and your help!