Replace every consonant sequence with its length in the given string | Function to return the converted string after replacing every consonant sequence with its length ; To store the resultant string ; Checking each character for consonant sequence ; Count the length of consonants sequence ; Add the length in the string ; Add the vowel ; Check for the last consonant sequence in the string ; Return the resultant string ; Driver code
def replaceConsonants ( string ) : NEW_LINE INDENT res = " " ; NEW_LINE i = 0 ; count = 0 ; NEW_LINE while ( i < len ( string ) ) : NEW_LINE INDENT if ( string [ i ] != ' a ' and string [ i ] != ' e ' and string [ i ] != ' i ' and string [ i ] != ' o ' and string [ i ] != ' u ' ) : NEW_LINE INDENT i += 1 ; NEW_LINE count += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT if ( count > 0 ) : NEW_LINE INDENT res += str ( count ) ; NEW_LINE DEDENT res += string [ i ] ; NEW_LINE i += 1 NEW_LINE count = 0 ; NEW_LINE DEDENT DEDENT if ( count > 0 ) : NEW_LINE INDENT res += str ( count ) ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = " abcdeiop " ; NEW_LINE print ( replaceConsonants ( string ) ) ; NEW_LINE DEDENT