To store the number of points has same x or y coordinates
xpoints = defaultdict ( lambda : 0 ) NEW_LINE ypoints = defaultdict ( lambda : 0 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT xpoints [ a [ i ] [ 0 ] ] += 1 NEW_LINE ypoints [ a [ i ] [ 1 ] ] += 1 NEW_LINE DEDENT