with open('log.log', 'rt', encoding='utf-8') as file: buf = [] result = [] for line in file: line = line.rstrip() if len(buf) and line.startswith('Warning'): result.append(' '.join(buf)) buf = [] buf.append(line) if len(buf): result.append(' '.join(buf)) print(result)
Standard input is empty
Standard output is empty
Traceback (most recent call last): File "./prog.py", line 1, in <module> with open('log.log', 'rt', encoding='utf-8') as file: FileNotFoundError: [Errno 2] No such file or directory: 'log.log'
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!