IndexError: list assignment index out of range python 3.4 -
in lempel-ziv decode methode indexerror code, know size 3, while len(lt) 2. converted pseudocode python code .
def decode(self,target): tlen = len(target) source = '' source += target[0] lt = ['',target[0]] loc = 1 size = 2 while loc < tlen: bitlen = ceil(log2(size)) index = self.bit_to_integer(target[loc:(loc+bitlen)]) seg = lt[index] if loc+bitlen < tlen: seg += target[loc+bitlen] size += 1 #print(size) #print(lt,size) lt[size] = seg loc += 1 source += seg loc += bitlen return source
this error message:
lt[size] = seg indexerror: list assignment index out of range
if want add third item list, use append
instead of assignment.
replace
lt[size] = seg
with
lt.append(seg)
Comments
Post a Comment