Part of my python script:
(I first made the dictionary “h”)
def histogram(L):
d= {}
for x in L:
if x in d:
d[x] +=1
else:
d[x] =1
return d
h=histogram(LIST)
for vhfile in vhfiles:
linelist=commands.getoutput('cat ' + vhfile).splitlines(True)
list1=[]
for line in linelist:
name1 = line.split()[0]
if int(h[name1]) <= 300:
list1.append(line)
Then I got error at “if” line:
File "/home/xug/scratch/mrfast/NA12878/dis_rm.py", line 51, in <module>
if int(h[name1]) <= 300:
KeyError: '080821_HWI-EAS301_0002_30ALBAAXX:1:46:1643:1310'
Any idea what happened here?
thx
You get a
KeyErrorwhen you try to look something up in thedict, and thedictdoesn’t contain that key.In this case, it appears that the key
'080821_HWI-EAS301_0002_30ALBAAXX:1:46:1643:1310'does not occur inh.