I typed this code to work as an arithmetic encoder (data compression), but I don't know what is wrong, it always gives zeros for 'high' and 'low'

here is a link illustrating the algorithm: http://cis.cs.technion.ac.il/Done_Proje ... ode19.html

and here is my code:

- Code: Select all
`import math`

text=raw_input("Type text here : ")

letters=list(text)

length=len(letters)

def prob(a):

return float(letters.count(a))/length

prob_list=[]

for a in letters:

prob_list=prob_list+[prob(a)]

print prob_list

def high_range(n):

del prob_list[n+1:]

return math.fsum(prob_list)

def low_range(n):

del prob_list[n:]

return math.fsum(prob_list)

low = 0

high = 1

for n in range(0,length):

code_range = high - low

high = low + code_range * high_range(n)

low = low + code_range * low_range(n)

print 'high: ' , high

print 'low: ', low