我有一个文件,我需要从中删除重复的对(用粗体标记)。在
输入文件:AT1G01010 = 0005634
**AT1G01010 = 0006355**
AT1G01010 = 0003677
AT1G01010 = 0007275
**AT1G01010 = 0006355
AT1G01010 = 0006355**
AT1G01010 = 0006888
**AT1G01020 = 0016125**
AT1G01020 = 0016020
**AT1G01020 = 0005739**
**AT1G01020 = 0016125**
AT1G01020 = 0003674
AT1G01020 = 0005783
**AT1G01020 = 0005739**
**AT1G01020 = 0006665
AT1G01020 = 0006665**
预期产量:
^{pr2}$
为了消除重复,我首先做了一本词典。在创建了字典之后,我尝试了以下代码:import sys
ara_go_file = open (sys.argv[1]).readlines()
ara_id_list = []
ara_go_list = []
for lines in ara_go_file:
split_lines = lines.split(' ')
ara_id = split_lines[0]
ara_id_list.append(ara_id)
go_id_split = split_lines[-1]
go_id = go_id_split.split('\n')[0]
ara_go_list.append(go_id)
ara_id_go_dic = dict (zip(ara_id_list, ara_go_list)) ##ara_id_go_dic (this is the name of the dict I have created)
new_dict = {} # made a new dict to copy the data into this n remove the duplicate pairs
for k in ara_id_go_dic.items():
if k[0] in new_dict:
if k[1] not in new_dict[k[0]]:
new_dict[k[0]].append(k[1])
else:
new_dict[k[0]]=[k[1]]
print new_dict
我不知道我到底在哪里犯了错误。在
请告诉我我的错误,否则如果有其他方法来删除重复的对。在