2 つの長いリストがあります。1 つは次のような形式の行を含むログ ファイルからのものです。
201001050843 blah blah blah <email@site.com> blah blah
もう 1 つのファイルは csv 形式です。csv 形式を維持しながら、ログ ファイルに電子メール アドレスが含まれていない file2 のすべてのエントリのリストを生成する必要があります。
ログ ファイルの例:
201001050843 blah blah blah <email@site.com> blah blah
201001050843 blah blah blah <email2@site.com> blah blah
File2 には以下が含まれます。
156456,bob,sagget,email@site.com,4564456
156464,bob,otherguy,email@anothersite.com,45644562
出力は次のようになります。
156464,bob,otherguy,email@anothersite.com,45644562
現在、ログからメールを取得し、次のように別のリストにロードします。
sent_emails =[]
for line in sent:
try:
temp1= line.index('<')
temp2 = line.index('>')
sent_emails.append(line[temp1+1:temp2])
except ValueError:
pass
そして、次のいずれかで file2 と比較します。
lista = mail_lista.readlines()
for line in lista:
temp = line.split()
for thing in temp:
try:
if thing.index('@'):
if thing in sent_emails:
lista.remove(temp)
except ValueError:
pass
newa.writelines(lista)
また:
for line in mail_listb:
temp = line.split()
for thing in temp:
try:
if thing.index('@'):
if thing not in sent_emails:
newb.write(line)
except ValueError:
pass
ただし、どちらもfile2のすべてを返します!
ご協力いただきありがとうございます。
編集:セットの推奨事項に感謝します。私が考えていたよりも大きな速度差がありました. さすがハッシュテーブル!私は間違いなくこれからもっと頻繁にセットを使用します.