import random keywords=[] with open('keywords.txt',encoding='utf-8') as f: for key in f.read().split(): keywords.append(key) with open('sel.txt',encoding='utf-8') as f: text=f.read() #generate questions about keywords in text lines = text.split('\n') random.shuffle(lines) def make_question(key,line): pos = line.rfind(key) if pos == -1: return None line = line[:pos] + '__' return line for line in lines[:100]: line = line.strip() for key in keywords: if key in line: #print(make_question(key,line)) print(line) print(key) break