Code:
def spin(text,brackets='[]'):
"""use "[choice1|choice2]" """
open_marker = 0
while text.find(brackets[0]) != -1:
counter = 0
for char in text:
if char == brackets[0]:
open_marker = counter
if char == brackets[1]:
part = text[open_marker+1:counter]
words = part.split('|')
word = random.choice(words)
text = text.replace(brackets[0]+part+brackets[1],word,1)
open_marker = 0
counter += 1
return text