How big are the two log files? Do they fit into memory?
If events do fit in memory, you can load all events into memory, strip newlines and put them into a set. A set has only unique elements and does not preserve the order.
The second file could be bigger because you can iterate line by line over the file object, which saves memory.
If events do fit in memory, you can load all events into memory, strip newlines and put them into a set. A set has only unique elements and does not preserve the order.
The second file could be bigger because you can iterate line by line over the file object, which saves memory.
# naive approach with open("f1.txt") as f1: events = set(line.strip() for line in f1) with open("f2.txt") as f2: for f2_line in f2: for event in events: if event in f2_line: print(f2_line, end="")
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!