def partition(phrase):
    words = phrase.split()
gaps = len(words) - 1
for i in range(1 << gaps):
    r = words[:1]
for word in words[1:]:
    if i & 1:
        r.append(word)
else:
    r[-1] += ' ' + word
i >>= 1
yield r
for part in partition('The really fast dog.'):
    pass
Split a string into all possible ordered phrases