У меня возникла проблема, не работает код приведенный ниже.
Даже не смею надеяться, что код хорошо работающий, мне хотя бы чтоб запустился.
Заранее спасибо!
Ошибка:
"C:\python>python test.py Traceback (most recent call last): File "test.py", line 26, in <module> strT1 = str(indexT) + listStr[i + 1] TypeError: 'str' object is not callable
C:\python>"
формально, ругается на эту строку
strT1 = str(indexT) + listStr[i + 1]
'''
Ziv Encoding
'''
str = "madma"
listStr = [] # для строки сообщения
listEn = []# для закодированного сообщения
for i in str:
listStr.append(i)
#print(listStr)
i = 0
while(i < len(listStr)):
if (i == 0):
strT = ""# string to build a element of listEn
strT = strT + "0" + listStr[i]
listEn.append(strT)
del strT
j = 0
while(j < len(listEn)):
for k in range (0, len(listEn)):
strT = ""
strT = listEn[k]
if (listStr[i] == strT[1:]):
indexT = i + 1 # rememer the index of element to build the element of listEn
strT1 = ""
strT1 = str(indexT) + listStr[i + 1]
listEn.append(strT1)
del indexT
del strT
del strT1
continue
else:
strT = ""# string to build a element of listEn
strT = strT + "0" + listStr[i]
listEn.append(strT)
del strT
j += 1
i += 1
print(listEn)