Jun-15-2021, 11:45 PM
block1 = """This is a bit of text but should pass completely """ block2 = """This bit of text will be found to be a real test of your patience """ for text_input in (block1, block2): line_count = 0 for line_count, line in enumerate(text_input.splitlines(), start=1): if "test" in line: print(f"There were {line_count-1} lines before finding 'test'") break else: print(f"test not found")
Output:test not found
There were 2 lines before finding 'test'