文件xxx和文件yyy包括相同的值,用以下代码可以找出相同的值。输出文件赛季zzz:
path = 'xxx'
path1 = 'yyy'
path2 = 'zzz'
f = open(path, encoding="utf-8")
f1 = open(path1, encoding="utf-8")
f2 = open(path2, "w", encoding="utf-8")
line = f.readlines()
line1 = f1.readlines()
length = len(line)
length1 = len(line1)
for i in range(length):
for j in range(length1):
line1[j] = line1[j].rstrip("\n")
if line1[j] in line[i]:
f2.write(f"{line1[j]}\n")
f1.close()
f2.close()
f.close()