[英]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.