human
I'm looking for a pythonic way to insert a space before capital letters
assistant
Here is some code to insert spaces before capital letters in string `text`

re.sub('([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))', '\\1 ', text)

#Warning: this code generation is experimental. Please inspect the code for any bugs before executing.