Replace consonants with next immediate consonants alphabetically in a String | Function to check if a character is vowel or not ; Function that replaces consonant with next immediate consonant alphabatically ; Start traversing the string ; if character is z , than replace it with character b ; if the alphabet is not z ; replace the element with next immediate alphabet ; if next immediate alphabet is vowel , than take next 2 nd immediate alphabet ( since no two vowels occurs consecutively in alphabets ) hence no further checking is required ; Driver code
def isVowel ( ch ) : NEW_LINE INDENT if ( ch != ' a ' and ch != ' e ' and ch != ' i ' and ch != ' o ' and ch != ' u ' ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT return True ; NEW_LINE DEDENT def replaceConsonants ( s ) : NEW_LINE INDENT for i in range ( len ( s ) ) : NEW_LINE INDENT if ( isVowel ( s [ i ] ) == False ) : NEW_LINE INDENT if ( s [ i ] == ' z ' ) : NEW_LINE INDENT s [ i ] = ' b ' ; NEW_LINE DEDENT else : NEW_LINE INDENT s [ i ] = chr ( ord ( s [ i ] ) + 1 ) ; NEW_LINE if ( isVowel ( s [ i ] ) == True ) : NEW_LINE INDENT s [ i ] = chr ( ord ( s [ i ] ) + 1 ) ; NEW_LINE DEDENT DEDENT DEDENT DEDENT return ' ' . join ( s ) ; NEW_LINE DEDENT s = " geeksforgeeks " ; NEW_LINE print ( replaceConsonants ( list ( s ) ) ) ; NEW_LINE