Find Unique ID and Domain Name of a Website from a string | Function to check if a character is alphabet or not ; Function to check if a character is a numeric or not ; Function to find ID and Domain name from a given ; Stores ID and the domain names ; Stores the words of S ; Stores the temporary word ; Traverse the S ; If the current character is space ; Push the curr in words ; Update the curr ; Otherwise ; If curr is not empty ; If length of ss is 10 ; Traverse the ss ; If j is in the range [ 5 , 9 ) ; If current character is not numeric ; Mark flag 1 ; Otherwise ; If current character is not alphabet ; Mark flag 1 ; If flag is false ; Assign ss to ID ; If sub formed by the first 3 character is " www " and last 3 character is " moc " ; Update the domain name ; Print ID and Domain ; Driver Code
def ischar ( x ) : NEW_LINE INDENT if ( ( x >= ' A ' and x <= ' Z ' ) or ( x >= ' a ' and x <= ' z ' ) ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return 0 NEW_LINE DEDENT def isnum ( x ) : NEW_LINE INDENT if ( x >= '0' and x <= '9' ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return 0 NEW_LINE DEDENT def findIdandDomain ( S , N ) : NEW_LINE INDENT ID , Domain = " " , " " NEW_LINE words = [ ] NEW_LINE curr = " " NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( S [ i ] == ' ▁ ' ) : NEW_LINE INDENT words . append ( curr ) NEW_LINE curr = " " NEW_LINE DEDENT else : NEW_LINE INDENT if ( S [ i ] == ' . ' ) : NEW_LINE INDENT if ( i + 1 == N or ( i + 1 < N and S [ i + 1 ] == ' ▁ ' ) ) : NEW_LINE INDENT continue NEW_LINE DEDENT DEDENT curr += S [ i ] NEW_LINE DEDENT DEDENT if ( len ( curr ) ) : NEW_LINE INDENT words . append ( curr ) NEW_LINE DEDENT for ss in words : NEW_LINE INDENT if ( len ( ss ) == 10 ) : NEW_LINE INDENT flag = 0 NEW_LINE for j in range ( 10 ) : NEW_LINE INDENT if ( j >= 5 and j < 9 ) : NEW_LINE INDENT if ( isnum ( ss [ j ] ) == 0 ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if ( ischar ( ss [ j ] ) == 0 ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT DEDENT DEDENT if ( not flag ) : NEW_LINE INDENT ID = ss NEW_LINE DEDENT DEDENT if ( ss [ 0 : 3 ] == " www " and ss [ len ( ss ) - 3 : ] == " com " ) : NEW_LINE INDENT Domain = ss [ 4 : len ( ss ) ] NEW_LINE DEDENT DEDENT print ( " ID ▁ = " , ID ) NEW_LINE print ( " Domain ▁ = " , Domain ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = " We ▁ thank ▁ ABCDE1234F ▁ for ▁ visiting ▁ us ▁ " " and ▁ buying ▁ products ▁ item ▁ AMZrr @ ! k . ▁ " N = len ( S ) NEW_LINE findIdandDomain ( S , N ) NEW_LINE DEDENT