I have a list containing of lists containing of x- and y-coordinates:
[[x1, y1], [x2, y2], … [xn, yn]].
I want the smallest and the largest x- and y-coordinates.
Since the x-coordinates are always at index 0, I want to compare all values at index 0 and find the min and the max. Same for index 1 (y-coordinates).
My solution right now:
listX = []
listY = []
for i in list:
listX.append(i[0])
listY.append(i[1])
xmin = min(listX)
xmax = max(listX)
ymin = min(listY)
ymax = max(listY)
Is there a better way? For example "Comparing all values at index 0 and find the min" in one line? In total this would be four lines instead of eight.
Context
I need this because I have a white image with not known shapes in it. For each shape I want to know the smallest rectangle there is to cover each shape completely. (4 shapes -> 4 rectangles not 1 rectangle for all). Different shapes can have the same color, but if that‘s the case they are not touching. Shapes of different colors could touch each other. The rectangles are allowed to overlap. This list in my question contains of all the pixels that are part of a certain shape.