How do I locate the row that matches the keyword for the second time?

topic description

I have a log file, which is roughly formatted as follows:
time1 keyword1
time2 keyword2
time3 keyword2
time4 keyword1
time5 keyword2
time6 keyword2

I need to extract the time based on the keywords keyword1 and keyword2, and the result is similar to:
time1 time3
time4 time6

but the keyword2 will appear twice, so I can"t locate it all the time.

sources of topics and their own ideas

the previous solution is to extract it all and then import the table filter. Now I want to use Python to implement it at once, but I am not very familiar with the list function in Python. I hope I can get some help.

related codes

/ / Please paste the code text below (do not replace the code with pictures)

this is the code written before

with open ("time.log"," ritual as encoding = "utf8") as F1, open ("result.txt", "w") as f2:

for line in f1.readlines():
    line = line.strip()
    if "keyword1" in line:
        k1Time = line[0:24]
    if "keyword2" in line:
        k2Time = line[0:24]
        f2.write(k1Time + "," + k2Time + "\n")

what result do you expect? What is the error message actually seen?

Jun.24,2021

< H1 > Code < / H1 >
with open('debug.log', 'r',encoding="utf8") as f1:
    for l in f1.readlines():
        line = l.split(" ")
        if 'keyword2' in line:
            print(l)
< H1 > result < / H1 >

time2 keyword2

time3 keyword2

time5 keyword2

time6 keyword2

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9fd77-1a8c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9fd77-1a8c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?