Traceback (most recent call last):
File "<pyshell#80>", line 1, in <module>
do_work()
File "C:\pythonwork\readthefile080410.py", line 14, in do_work
populate_frequency5(e,data)
File "C:\pythonwork\readthefile080410.py", line 157, in populate_frequency5
data=medications_minimum3(data,[drug.upper()],1)
File "C:\pythonwork\readthefile080410.py", line 120, in medications_minimum3
counter[row[11]]+=1
TypeError: unhashable type: 'list'
我收到这条线上面的错误:蟒蛇:unhashable类型的错误
data=medications_minimum3(data,[drug.upper()],1)
(我自己也尝试drug.upper()不带括号)
这里是一个预览此功能:
def medications_minimum3(c,drug_input,sample_cutoff): #return sample cut off for # medications/physician
d=[]
counter=collections.defaultdict(int)
for row in c:
counter[row[11]]+=1
for row in c:
if counter[row[11]]>=sample_cutoff:
d.append(row)
write_file(d,'/pythonwork/medications_minimum3.csv')
return d
有没有人知道我在做什么错在这里?
我知道什么是必须是错的是我调用这个函数的方式,因为我把从不同的位置,这个功能并能正常工作:
d=medications_minimum3(c,drug_input,50)
非常感谢您的帮助!
为什么在失败的调用中''drug.upper()]'方括号? – 2010-08-04 22:10:13
而且它也没有在功能上使用,没有提及drug_input – jcubic 2010-08-04 22:18:18
@jcubic:很好。这可能意味着代码已经被过多地编辑以便在这里发布以至于毫无价值。 – 2010-08-04 22:25:05