[英]How to fix TypeError: unhashable type: 'dict'
**解壓Function:從壓縮function加載文件bin
def lzwDecompressionText () :
loadCompressed = open ("CompreText.bin","rb")
compressed = pickle.load(loadCompressed)
print("", compressed)
dictionary =defaultdict(dict)
lenDictionary = 256
decompressed_data = ""
string=""
for i in range(256):
dictionary[i] = chr(i)
Traceback (most recent call last):
File "c:/Users/anton/Documents/GitHub/Project-LZW/LZW-Project/test.py", line 21, in <module>
lzwDecompressionText()
File "c:\Users\anton\Documents\GitHub\Project-LZW\LZW-Project\textLzw.py", line 70, in lzwDecompressionText
if not (code in dictionary):
TypeError: unhashable type: 'dict'
for code in compressed:
if not (code in dictionary):
dictionary[code] = string + (string[0])
decompressed_data += dictionary[code]
if not(len(string) == 0):
dictionary[lenDictionary] = string + (dictionary[code][0])
lenDictionary += 1
string = dictionary[code]
似乎至少有一些compressed
(從腌制文件加載)中的code
值恰好是dict
類型,這與您對int
的期望相反。
另請參閱: TypeError: Unhashable type 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.