#NEWLINE# def merge( first , second ) : #NEWLINE# #INDENT# '\n    Recursively merges two dictionnaries.\n\n    Second dictionnary values will take precedance over those from the first one.\n    Nested dictionnaries are merged too.\n\n    :param dict first: The first dictionnary\n    :param dict second: The second dictionnary\n    :return: the resulting merged dictionnary\n    :rtype: dict\n    ' #NEWLINE# if ( not isinstance ( second , dict ) ) : #NEWLINE# #INDENT# return second #NEWLINE# #UNINDENT# result = deepcopy ( first ) #NEWLINE# for ( key , value ) in iteritems ( second ) : #NEWLINE# #INDENT# if ( ( key in result ) and isinstance ( result [ key ] , dict ) ) : #NEWLINE# #INDENT# result [ key ] = merge ( result [ key ] , value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# result [ key ] = deepcopy ( value ) #NEWLINE# #UNINDENT# #UNINDENT# return result