我希望找到仅附加唯一项目 numlookup 和 Wholetoken 的方法。有没有好的方法来做到这一点?
numlookup = defaultdict(list)
wholetoken = defaultdict(list)
#mydata is file containing mutation description
mydata = open('/mutation_summary.txt')
for line in csv.reader(mydata, delimiter='\t'):
code = re.match('[a-z](\d+)[a-z]', line[-1], re.I)
if code:
numlookup[line[-2]].append(code.group(1))
wholetoken[line[-2]].append(code.group(0))
当我尝试使用 set 时,当我调用 lookup(id) 和 Wholelookup(id) 时出现错误:TypeError: 'set' object is not callable
lookup =set()
wholelookup =set()
with open('mutation_summary.txt') as mydata:
for line in csv.reader(mydata, delimiter='\t'):
code = re.match('[a-z](\d+)[a-z]', line[-1], re.I)
if code:
lookup.add(code.group(1))
wholelookup.add(code.group(0))