I'm trying to create all possible in order combinations of a word's syllables.
For example, I have the word overflowing and I have a list of it's syllables ['o', 'ver', 'flow', 'ing']. I would like the output to show all the possible combinations of combining the syllables to make the word: [('o', 'ver', 'flow', 'ing'), ('o', 'verflow', 'ing'), ('o', 'verflowing'), ('overflowing'), ('over', 'flow', 'ing'), ...].
Here is my attempt:
syllable_list = ['o', 'ver', 'flow', 'ing']
list_length = len(syllable_list)
for x in range(0, list_length):
for y in range(0, list_length):
if syllable_list[y:x+1]:
before = ""
middle = ""
after = ""
if syllable_list[0:y]:
before = ["".join(syllable_list[0:y])]
if syllable_list[x+1:]:
after = ["".join(syllable_list[x+1:])]
middle = ["".join(syllable_list[y:x+1])]
print(before, middle, after)
The output is:
['o'] ['verflowing']
['over'] ['flowing']
['o'] ['ver'] ['flowing']
['overflow'] ['ing']
['o'] ['verflow'] ['ing']
['over'] ['flow'] ['ing']
['overflowing']
['o'] ['verflowing']
['over'] ['flowing']
['overflow'] ['ing']
All the combinations are there, with some duplicates, and I'm missing the ['o', 'ver', 'flow', 'ing'] case. What am I doing wrong? Is there a library that already handles this so I don't have to recreate the wheel?