How can I reduce the time?
<p>I'm trying to reduce the time when I compress a file from a string, and after I descompress. Dic is the dictionary obtained from the Huffman algorithm. The input for the compress function is a .txt, for the descompress function the input file, is the output file from the compress function.</p>

<pre><code>def compress(dic,archivo,outfile):
    content = (open(archivo,'rt', encoding = 'utf-8')).read()
    res = ''
    for ch in content:
       res = res + dic[ch]
    outf = open(outfile,'wb')
    pickle.dump(int('1'+ res,2),outf)
    outf.close()
    pass

def descompress(dic,infile,outfile):
    data = bin(pickle.load(open(infile,'rb')))
    k = 1
    chain = ''
    cadena = ''
    for i in data:
        if k&gt;3:
            chain = chain + i           
            if (chain in dic) == True: 
               cadena = cadena + dic[chain]
               chain = ''      
        else:
           k = k + 1
    outfile = open(outfile,'w',encoding = 'utf-8')
    outfile.write(cadena)
    pass
</code></pre>

<p>Well, I start reading with k=3 at the code in the function descompress because it starts with '0b1' and this is nothing. Sorry for my bad english.</p>