How to filter out partially similar strings from two lists and make one list? I have following two lists.
List1
m64041_200717_231916/100664277/0_42364 id=2440
m64041_200717_231916/100008029/0_42112 id=244006
m64041_200717_231916/100665802/0_46854 id=2440067
m64041_200717_231916/100008044/0_60161 id=24400
m64041_200717_231916/100928073/0_11804 id=2440152
m64041_200717_231916/10094492/0_44157 id=2440199
m64041_200717_231916/100008373/4102_50601 id=2440234

List2
m64041_200717_231916/100664277/0_42364
m64041_200717_231916/100665802/0_46854
m64041_200717_231916/100928073/0_11804
m64041_200717_231916/10094492/0_44157

These are sequence read ids from a genome file. List1 contains all the ids from the List2 but with some id numbers (id=2440). So the sequence ids are only similar to some extent. I want to compare these two files and I need to filter out List2 sequence ids from List one (with id numbers) as below.
Output.
m64041_200717_231916/100664277/0_42364 id=2440
m64041_200717_231916/100665802/0_46854 id=2440067
m64041_200717_231916/100928073/0_11804 id=2440152
m64041_200717_231916/10094492/0_44157 id=2440199

I will be grateful if someone can help me with this issue.
You really need to learn some python :)
with open('/path/list2.txt', 'r') as fin:
    to_keep = set([])
    for line in fin:
        to_keep.add(line.strip())
        
with open('/path/list1.txt', 'r') as fin:
    with open('/path/list3.txt', 'w') as fout:
        for line in fin:
            if line.strip().split(' ')[0] in to_keep:
                fout.write(line)