human
Write me a code to maximum Squares possible parallel to both axes from N distinct points and the other steps required given the following:
Maximum Squares possible parallel to both axes from N distinct points | Function that returns the count of squares parallel to both X and Y - axis from a given set of points.
Initialize result.
Initialize a set to store points.
Initialize a map to store the points in the same vertical line.
Store the points in a set.
Store the points in the same vertical line i . e . with same X co - ordinates.
Check for every two points in the same vertical line.
Check if other two point are present or not.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to maximum Squares possible parallel to both axes from N distinct points and the other steps required.
 def countSquares ( X , Y , N ) :
	count = 0 ;
	points = [ ] ;
	vertical = dict . fromkeys ( X , None ) ;
	for i in range ( N ) :
		points . append ( ( X [ i ] , Y [ i ] ) ) ;
	for i in range ( N ) :
		if vertical [ X [ i ] ] is None :
			vertical [ X [ i ] ] = [ Y [ i ] ] ;
		else :
			vertical [ X [ i ] ] . append ( Y [ i ] ) ;
	for line in vertical :
		X1 = line ;
		yList = vertical [ line ] ;
		for i in range ( len ( yList ) ) :
			Y1 = yList [ i ] ;
			for j in range ( i + 1 , len ( yList ) ) :
				Y2 = yList [ j ] ;
				side = abs ( Y1 - Y2 ) ;
				X2 = X1 + side ;
				if ( X2 , Y1 ) in points and ( X2 , Y2 ) in points :
					count += 1 ;
	return count ;
if __name__ == " _ _ main _ _ " :
	X = [ 0 , 2 , 0 , 2 ] ; Y = [ 0 , 2 , 2 , 0 ] ;
	N = len ( X ) ;
	print ( countSquares ( X , Y , N ) ) ;