こんにちは、私はこのスクリプトを持っています。このスクリプトは、2 つのファイルを 2 つのリストに分割し、それらを 1 つのリストにまとめて 1 つのファイルに書き込む必要がありますが、問題は、ファイルの 1 つに 1+ インデックスのリストの長さがある可能性があることです。それらのいくつかは 5 であるため、そのうちの 10 であるため、最初と 2 番目のリストの長さが必要です。それらを 1 つのリストに追加し、データ間の [] と ' なしで 1 つのファイルに書き込みます。脚本
import re
f = open('Firsttext.txt', 'r')
d = open('second.txt', 'r')
w = open('combination.txt','w')
s=""
filtred=[]
Mlines=f.readlines()
Wlines=d.readlines()
for line in Wlines:
Wspl=line.split()
for line2 in Mlines:
Mspl=line2.split()
if ((Mspl[0]).lower()==(Wspl[0])):
Wspl.append(Mspl[1])
print (Wspl)
s="\t".join(Wspl)+"\n"
if s not in filtred:
filtred.append(s)
break
for x in filtred:
w.write(x)
f.close()
d.close()
w.close()