def search_gen(lines, pattern, history=5): """ Search for a pattern using a generator function """ previous_lines = deque([], history) for line in lines: if pattern in line: yield line, previous_lines previous_lines.append(line)
def search_gen(lines, pattern, history=5): """ Search for a pattern using a generator function """ previous_lines=deque([], history) for line in lines: if pattern in line: yield line, previous_lines previous_lines.append(line)
def search_no_gen(lines, pattern, his): """ Search for a pattern in a set of lines without using a Generator function """ new_line = [] previous_lines = deque([], his) for line in lines: if pattern in line: new_line.append((line, previous_lines[:])) previous_lines.append(line) return new_line
def search_no_gen(lines,pattern, his): """ Search for a pattern in a set of lines without using a Generator function """ new_line=[] previous_lines=deque([], his) for line in lines: if pattern in line: new_line.append ( (line, previous_lines[:])) previous_lines.append(line) return new_line