# Find the minimum bounding rectangle (MBR), that is, the minimum and maximum x and y coordinates for a dataset. import sys # for maximum 32-bit integer minx = sys.maxint # initialize minimum values to largest possible positive integer miny = sys.maxint maxx = -sys.maxint # initialize maximum values to largest possible negative integer maxy = -sys.maxint data = {(1,0), (0,1), (-1,0), (0, -1)} # a diamond-shaped polygon represented by 4 x,y tuples for point in data: # go through data, one tuple at a time. The first element (0) is x, the second (1) is y if point[0] < minx: # is this point's x value less than the minimum x so far? minx = point[0] # if so, replace the previous value of minx with the value we just found if point[1] < miny: # do the same for all our other extreme values miny = point[1] if point[0] > maxx: maxx = point[0] if point[1] > maxy: maxy = point[1] # After the for loop, our MBR is held in minx, miny, maxx, maxy print 'for data = ' + str(data) print 'minx = ' + str(minx) + ', miny = ' + str(miny) + ', maxx = ' + str(maxx) + ', maxy = ' + str(maxy)