我是 python 新手,如果这不是最好/最快的方法,请纠正我。我创建了一个字典,为每个键分配了多个值。在codonDict
我只包含了 1 个键和它的一些值(会有更多)。现在我有一个我在calls
这里调用的文件。我想要做的是#CHROM
在文件中找到与 对应的键,然后搜索键值以查看它是否包含对应的POS
.
codonDict = defaultdict(<type 'list'>, {'HE667775': [106690, 106692, 106694, 106696, 106698, 106700, 106702, 106704, 106706, 106708, 106710, 106712, 106714, 106716, 106718, 106720, 106722, 106724, 106726, 106728, 106730, 106732, 106734, 106736, 106738, 106740, 106742, 106744, 106746, 106748, 106750, 106752, 106754, 106756, 106758, 106760, 106762, 106764, 106766, 106768, 106770, 106772, 106774, 106776, 106778, 106780, 106782, 106784, 106786, 106788, 106790, 106792, 106794, 106796, 106798, 106800, 106802, 106804, 106806, 106808, 106810, 106812, 106814, 106816, 106818, 106820, 106822, 106824, 106826, 106828, 106830, 106832, 106834, 106836]})
calls
文件:
#CHROM POS
HE667775 106824
HE667775 24
HE667775 106824
因此,从这个样本数据中,所需的输出将append
是test
我试过的:
test = []
line = calls.readline()
while len(line) > 1:
#for line in calls:
objects = line.split()
pos = int(objects[1])
chrom = objects[0]
#if scaf in codonDict and pos associated with that key
for scaf, position in codonDict.itervalues():
if pos == position and chrom in scaf:
test.append(line)
print test
错误:
ValueError: too many values to unpack
编辑:
这是完整的错误回溯,但是行不同,所以我相信上面代码中的第 28 行pos = int(objects[1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 28, in main
ValueError: too many values to unpack