[英]defining dictionary in python getting TypeError: unhashable type: 'dict'
[英]passing dictionary as parameter in csp python gives unhashable type: 'dict'
我在 python 中应用 CSP 在将字典作为参数传递给 python 中的方法时出现问题
officerDomain = range(0, 2**scheduleDays-1)
solver = MinConflictsSolver()
problem = Problem(solver)
officers = []
officers.append({'name':'Ryan', 'rank':'3'})
officers.append({'name':'Mond', 'rank':'1'})
officers.append({'name':'Eric', 'rank':'3'})
for officer in officers:
print(officer)
problem.addVariable(officer, officerDomain)
在列表中传递字典时,它会给出错误unhashable type: 'dict'
让我们阅读文档:
addVariable(self, variable, domain)
参数:变量- Object 表示问题变量(类型=哈希对象)
所以你不能使用字典(在这种情况下是官员),因为它是不可散列的。 例如,尝试使用officer["name"]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.