First, you need to read the text file into a string; find the pattern “{([a-z|]+)}” using regex, split them by “|” to make a list as random words. It could be achieved as the following:
import re, random
seed = []
matches = re.findall('{([a-z|]+)}', open('bio.txt', 'r').read())
[seed.extend(i.split('|')) for i in matches]
input = random.choice(seed)
solved python identificare random syntax in text