Count pairs of similar rectangles possible from a given array | ''Python 3 Program for the hashmap Approach ; ''Get the count of all pairs of similar rectangles ; '' Initialize the result value and  map to store the ratio to the rectangles ; '' Calculate the rectangular ratio and save them ; '' Calculate pairs of similar rectangles from its common ratio ; ''Driver code
from collections import defaultdict NEW_LINE def getCount ( rows , columns , sides ) : NEW_LINE INDENT ans = 0 NEW_LINE umap = defaultdict ( int ) NEW_LINE for i in range ( rows ) : NEW_LINE INDENT ratio = sides [ i ] [ 0 ] / sides [ i ] [ 1 ] NEW_LINE umap [ ratio ] += 1 NEW_LINE DEDENT for x in umap : NEW_LINE INDENT value = umap [ x ] NEW_LINE if ( value > 1 ) : NEW_LINE INDENT ans += ( value * ( value - 1 ) ) / 2 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT sides = [ [ 4 , 8 ] , [ 10 , 20 ] , [ 15 , 30 ] , [ 3 , 6 ] ] NEW_LINE rows = 4 NEW_LINE columns = 2 NEW_LINE print ( int ( getCount ( rows , columns , sides ) ) ) NEW_LINE DEDENT