Find one extra character in a string | Python Program to find extra character in one string ; Determine string with extra character ; Add Character codes of both the strings ; Add last character code of large string ; Minus the character code of smaller string from the character code of large string The result will be the extra character code ; Driver code
def findExtraCharacter ( s1 , s2 ) : NEW_LINE INDENT smallStr = " " NEW_LINE largeStr = " " NEW_LINE if ( len ( s1 ) > len ( s2 ) ) : NEW_LINE INDENT smallStr = s2 NEW_LINE largeStr = s1 NEW_LINE DEDENT else : NEW_LINE INDENT smallStr = s1 NEW_LINE largeStr = s2 NEW_LINE DEDENT smallStrCodeTotal = 0 NEW_LINE largeStrCodeTotal = 0 NEW_LINE i = 0 NEW_LINE while ( i < len ( smallStr ) ) : NEW_LINE INDENT smallStrCodeTotal += ord ( smallStr [ i ] ) NEW_LINE largeStrCodeTotal += ord ( largeStr [ i ] ) NEW_LINE i += 1 NEW_LINE DEDENT largeStrCodeTotal += ord ( largeStr [ i ] ) NEW_LINE intChar = largeStrCodeTotal - smallStrCodeTotal NEW_LINE return chr ( intChar ) NEW_LINE DEDENT s1 = " abcd " NEW_LINE s2 = " cbdae " NEW_LINE extraChar = findExtraCharacter ( s1 , s2 ) NEW_LINE print ( " Extra ▁ Character : " , extraChar ) NEW_LINE