with open("polish_wiki_excerpt.in", encoding="utf8") as f: lines = f.readlines() for line in lines: if "Pies " in line or " pies " in line or "pies\n" in line: print(line.strip("\n"))