Change the given string according to the given conditions | Function to proofread the spells ; Loop to iterate over the characters of the string ; Push the current character c in the stack ; Check for Rule 1 ; Check for Rule 2 ; To store the resultant string ; Loop to iterate over the characters of stack ; Return the resultant string ; Given string str ; Function Call
def proofreadSpell ( str ) : NEW_LINE INDENT result = [ ] NEW_LINE for c in str : NEW_LINE INDENT result . append ( c ) NEW_LINE n = len ( result ) NEW_LINE if ( n >= 3 ) : NEW_LINE INDENT if ( result [ n - 1 ] == result [ n - 2 ] and result [ n - 1 ] == result [ n - 3 ] ) : NEW_LINE INDENT result . pop ( ) NEW_LINE DEDENT DEDENT n = len ( result ) NEW_LINE if ( n >= 4 ) : NEW_LINE INDENT if ( result [ n - 1 ] == result [ n - 2 ] and result [ n - 3 ] == result [ n - 4 ] ) : NEW_LINE INDENT result . pop ( ) NEW_LINE DEDENT DEDENT DEDENT resultStr = " " NEW_LINE for c in result : NEW_LINE INDENT resultStr += c NEW_LINE DEDENT return resultStr NEW_LINE DEDENT str = " hello " NEW_LINE print ( proofreadSpell ( str ) ) NEW_LINE