Decode a given string by removing duplicate occurrences | Function to count the appearances of each character ; If the character is lower case ; If the character is uppercase ; If the character is a punctuation mark ; Function to decode the given encoded string ; Iterate the given string str ; Find the index of the next character to be printed ; Driver code
def findRepetition ( a ) : NEW_LINE INDENT if a <= ' z ' and a >= ' a ' : NEW_LINE INDENT return ord ( a ) - 97 NEW_LINE DEDENT elif a <= ' Z ' and a >= ' A ' : NEW_LINE INDENT return ord ( a ) - 65 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT def decodeString ( str_ ) : NEW_LINE INDENT output = " " NEW_LINE i = 0 NEW_LINE while ( i < len ( str_ ) ) : NEW_LINE INDENT output += str_ [ i ] NEW_LINE i += findRepetition ( str_ [ i ] ) + 1 NEW_LINE DEDENT print ( " Decrypted ▁ code ▁ is ▁ { " + output + " } " ) NEW_LINE DEDENT str_ = " abbbb ▁ acccdddd " NEW_LINE decodeString ( str_ ) NEW_LINE