Modify the string by swapping continuous vowels or consonants | Function to check if a character is a vowel ; Function to swap two consecutively repeated vowels or consonants ; Traverse through the length of the string ; Check if the two consecutive characters are vowels or consonants ; swap the two characters ; Driver code
def isVowel ( c ) : NEW_LINE INDENT c = c . lower ( ) ; NEW_LINE if ( c == ' a ' or c == ' e ' or c == ' i ' or c == ' o ' or c == ' u ' ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT return False ; NEW_LINE DEDENT def swapRepeated ( string ) : NEW_LINE INDENT for i in range ( len ( string ) - 1 ) : NEW_LINE INDENT if ( ( isVowel ( string [ i ] ) and isVowel ( string [ i + 1 ] ) ) or ( not ( isVowel ( string [ i ] ) ) and not ( isVowel ( string [ i + 1 ] ) ) ) ) : NEW_LINE INDENT ( string [ i ] , string [ i + 1 ] ) = ( string [ i + 1 ] , string [ i ] ) ; NEW_LINE DEDENT DEDENT string = " " . join ( string ) NEW_LINE return string ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = " geeksforgeeks " ; NEW_LINE print ( swapRepeated ( list ( string ) ) ) ; NEW_LINE DEDENT