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
79 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,200 points
58 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
• 2,450 points
19 views
0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,710 points
65 views
+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 168 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,200 points
82 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,320 points
43 views