Compress and decompress string in Python

0 votes
Please write a program to compress and decompress the string. Which module should be used?
Jul 23 in Python by Ritu
686 views

1 answer to this question.

0 votes

You can use the zlib module available in python to compress and decompress the string. Refer to the code below:

import zlib
text="Hello world"
comp=zlib.compress(text)
print("Compressed: ", comp)
decomp=zlib.decompress(text)
print("Decompressed: ", decomp)
answered Jul 23 by Bhagavath

Related Questions In Python

0 votes
1 answer

How can I print variable and string on same line in Python?

Use , to separate strings and variables while printing: print ...READ MORE

answered Sep 17, 2018 in Python by Priyaj
• 56,960 points
80 views
0 votes
1 answer

Is it possible to print a string and a variable in a single print statement in Python?

This can be done using simple string ...READ MORE

answered Jul 15 in Python by Neel
• 3,010 points
39 views
+1 vote
1 answer
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 405 views
+4 votes
6 answers
+1 vote
1 answer

Python: Print variable and string in same line

For a better understanding you can refer ...READ MORE

answered Oct 30, 2018 in Python by Priyaj
• 56,960 points
130 views
0 votes
1 answer

Replace First and Last Word of String in the Most Pythonic Way

import re a = " this is a ...READ MORE

answered Aug 22, 2018 in Python by ariaholic
• 7,340 points
61 views