hi there!
i'm have a biiig trouble. I've make a simple chatbot, as can learning.
The problem is, that I can't insert data into the dictionary without a error.
here is the code:
codes = {}
def arraycompare(array1, array2):
l = 0
for i in array1:
for j in array2:
if i == j:
l = l + 1
return l
while True:
try:
obj = open("answers.txt", "r")
codes = dict(obj.read())
obj.close()
except IOError:
pass
inpt = raw_input("<<<").split()
fzylgc = {}
for i in codes:
fzylgc[i] = arraycompare(inpt, i)
Bv = 0
key = None
for i in fzylgc:
if fzylgc[i] > bv:
key = i
Bv = Bv + 1
if Bv <= 1:
inpt2 = raw_input("?...")
codes[inpt] = inpt2
obj = open("answers.txt", "w")
obj.write(str(codes))
obj.close()
else:
print codes[key]
when I'm running the program, this is ganna happend:
>>>
<<<Hello
?...hi There!!
Traceback (most recent call last):
File "C:\develop\module test\AI.py", line 32, in <module>
codes[inpt] = inpt2
TypeError: unhashable type: 'list'
>>>
I hope that someones can help me and that I've explain enought, but the code is saying the most, right