1

私はこのファイルを持っています:

domain|nsservers
virus.am.|['ns101.yourhostservice.com.', 'ns102.yourhostservice.com.']
rochemme.ae.|['auhans1.ecompany.ae.', 'auhans2.ecompany.ae.', 'dxbans1.ecompany.ae.', 'dxbans2.ecompany.ae.']
virus.am.|['ns101.yourhostservice.com.', 'ns102.yourhostservice.com.','ns103.yourhostservice.com.']
rochemme.ae.|['auhans2221.ecompany.ae.']

この形式で新しいファイルを作成したいと思います。

domain|list of all unique nsservers
 virus.am.|['ns101.yourhostservice.com.', 'ns102.yourhostservice.com.','ns103.yourhostservice.com.']
 rochemme.ae.|['auhans1.ecompany.ae.', 'auhans2.ecompany.ae.', 'dxbans1.ecompany.ae.', 'dxbans2.ecompany.ae.','auhans2221.ecompany.ae.']

これが私が使用したコードです。しかし、それは私が望む結果を与えません:

from collections import defaultdict


file = './test'
dns_dic = defaultdict(set)

f = open(file,'r')
for line in f:
    line = line.strip()
    domain,nslist = line.split('|')
    if domain in dns_dic:
        dns_dic[domain].append(nslist)
    else:
        dns_dic[domain] = (nslist)
print(dns_dic)

これらのリストをキー (この場合はドメイン名) の一意の値に結合するにはどうすればよいですか?

4

1 に答える 1