Once the corrected CristopheD clause is corrected, your function returns this:
['hallo', 'hello', 'hillo', 'hollo', 'hullo', 'hella', 'helle', 'helli', 'hello', 'hellu']
... therefore it returns some of the possible combinations, but not all of them.
This is because he takes each vowel in the word in turn and replaces it with each vowel in turn, and then moves on to the next vowel in the word - but not taking into account the previous vowels (s) that he found when he falls into the next. Here's a recursive solution that works for words with any number of vowels:
import re VOWELS = "aeiou" RE_VOWEL = re.compile("[%s]" % VOWELS) def helper(parts): if len(parts) == 1: yield parts[0] else: for vowel in VOWELS: for item in helper([vowel.join(parts[:2])] + parts[2:]): yield item def vowels(word): parts = re.split(RE_VOWEL, word) return list(helper(parts))
source share