I have two large lists each with thousands of elements as follows.
I wanted to extract the pair of elements by matching the strings between two lists.
However, it is very slow. How can I speed it up ?
import os, glob
list1 = glob.glob("/data0/*.txt")
list2 = glob.glob("/data1/*.txt")`
with open("result.txt", "w") as fout:
for i1 in list1:
tobematched1 = os.path.basename(i1).split(".")[0] + "_" + os.path.basename(i1).split(".")[3]
for i2 in list2:
tobematched2 = os.path.basename(i2).split(".")[0] + "_" + os.path.basename(i2).split(".")[3]
if tobematched1 == tobematched2:
fout.write(i1 + ";" + i2 + "\n")`
#This problem is not about common elements comparison as in the Common elements comparison between 2 lists
My question is to deal with strings
between two lists.