Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- letras = "abcdefghijklmnopqrstuvxwyz"
- arquivo = open ('to be or not be.txt','r')
- contador = range(0, len(letras))
- contador = map(lambda x: 0, contador)
- estatistica = contador
- texto = ""
- for linha in arquivo:
- temp = linha.lower()
- texto += temp
- it = 0
- for it in range(len(letras)):
- contador[it] += texto.count(letras[it])
- soma = reduce(lambda x,y:x+y,contador)
- it = 0
- for it in range(len(letras)):
- estatistica[it] = math.floor(contador[it])/soma
- #print letras[it],":", estatistica
- codigo = ('0','10','110','1110','11110','111110','1111110','11111110','111111110','1111111110','11111111110','111111111110','1111111111110','11111111111110','111111111111110','1111111111111110','11111111111111110','111111111111111110','1111111111111111110','11111111111111111110','111111111111111111110','1111111111111111111110','11111111111111111111110','111111111111111111111110','1111111111111111111111110','11111111111111111111111110')
- i = 0
- for i in range(len(letras)):
- texto.replace(letras[i],codigo[i])
- print "Texto normal:", len(texto)
- it = 0
- texto_code = texto
- maior = estatistica[0]
- j = 0
- k = 0
- for j in range(len(estatistica)):
- it = 0
- k = 0
- for it in range(len(estatistica)):
- if estatistica[it] > maior:
- maior = estatistica[it]
- k = it
- texto_code = texto_code.replace(letras[k],codigo[0])
- codigo = codigo[1:len(codigo)]
- estatistica.remove(estatistica[k])
- letras.replace(letras[k],'')
- if len(estatistica)>0:
- maior = estatistica[0]
- print " Numero de caracteres:",soma
- print " Texto Codificado:",len(texto_code)
Add Comment
Please, Sign In to add comment