s = "there once was a man from nantucket" vowels = 'aeiou' phrase = s.split() def procWord(word): cluster = False for i in range(len(word)): if word[i] in vowels and not cluster: return word + 'way' elif word[i] in vowels and cluster: return word[i:] + word[:i] + 'ay' else: cluster = True return word out = '' for word in phrase: out += procWord(word) + ' ' print(out)