Jul-12-2020, 03:08 PM
Collect all messages in intermediate and append to final data only when there is a timestamp (and there is data in intermediate)
intermediate = [] finalData = [] file = open('sample.txt', 'r', encoding="utf8") for lines in file: if startsWithDate(lines) and intermediate: finalData.append(' '.join(intermediate)) intermediate.clear() intermediate.append(lines)