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'
Tôi nhận được lỗi trên trên dòng này:python: unhashable loại lỗi
(drug.upper Tôi cũng đã cố gắng() không có ngoặc vuông)data=medications_minimum3(data,[drug.upper()],1)
Đây là một bản xem trước của chức năng này:
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
Có ai biết tôi đang làm gì sai ở đây không?
Tôi biết rằng những gì phải là sai lầm là cách tôi gọi chức năng này, bởi vì tôi gọi chức năng này từ một địa điểm khác nhau và nó hoạt động tốt:
d=medications_minimum3(c,drug_input,50)
Cảm ơn bạn rất nhiều vì sự giúp đỡ của bạn!
Tại sao bạn có dấu ngoặc vuông quanh '[drug.upper()]' trong cuộc gọi không thành công? –
Và nó cũng không được sử dụng trong hàm, không có tham chiếu đến drug_input – jcubic
@jcubic: Tốt bắt. Điều đó có thể có nghĩa là mã đã được chỉnh sửa rất nhiều để đăng bài ở đây là vô giá trị. –