I am making a multiword anagram generator, and for this I need to insert a number of spaces in random positions throughout a given string. The inserted spaces must also not be adjacent to one another, nor can they be at the end or beginning of the string. If someone could show me how to do this, I would very much appreciate it.
Here is my current code:
import enchant
import itertools
d = enchant.Dict("en_US")
while True:
text = input('Enter text to be anagrammed: ')
perms = set([''.join(p) for p in itertools.permutations(text.replace(' ', ''))])
anagrams = []
for i in perms:
if d.check(i) == True:
anagrams.append(i)
print(anagrams)
For example, for the input 'fartshoes', if I wanted to insert two spaces in it, a possible output would be 'far tsho es'.