AI

03 May, 2009

An elementary Python data compression question

General — Posted by aisci @ 20:21

Hi all,
Though I don't work in data compression, but for learning purpose only I ran a program very similar to the one given in version specific tutorial from www.python.org.  (ch 11, tut.pdf). The two programs are:

PROGRAM 1

import zlib
s = "witch which has which witches wrist watch"
print "Original String is ::%s:: and length of the string is ::%d::" %(s,len(s))
t = zlib.compress(s)
print "Compressed String is ::%s:: and length of the string is ::%d::" %(t,len(t))
print "Decompressed String is ::%s:: and length of the decompressed string is ::%d::" %(zlib.decompress(t),len(zlib.decompress(t)))

PROGRAM 2

import zlib
s = "witch which has which witches wrist watch"
print "Original String is ::%s:: and length of the string is ::%d::" %(s,len(s))
t = zlib.compress(s)
print "Compressed String is ::%s:: and length of the string is ::%d::" %(t,len(t))
print "Decompressed String is ::%s:: and length of the decompressed string is ::%d::" %(zlib.decompress(t),len(zlib.decompress(t)))

Now the problem is that:
in program2, the 'len(t)', i.e. length of the compressed string is greater than length of the original string!!! In program 1, this 'apparent anomaly' doesn't occur, and this is the string used in the python.org tutorial.

Can anybody provide an explanation? At this point, I don't want to read a few hundred pages on data compression to find out the answer.

Thanks in advance,
Abhishek Pathak.


Comments

  1. I had a same problem/question some time ago but it wasnt so important that time and I forgot about it, but it wouldnt hurt if anybody could come up with something...
    David Sims

    Posted by Fuel — 10 Feb 2010, 16:29

  2. thanks for posting this, useful and much appreciated. rather new in this stuff, I pay much attention to self-education, so appreciate any useful info on the topic

    Posted by Torrents Search — 27 Oct 2009, 17:38


Add comment

Add comment
 authimage

Powered by LifeType