Question: **python Most of us have some archiver utility software like Winrar or 7-Zip installed on our personal computers. They help combine multiple files/folders into a
**python
Most of us have some archiver utility software like Winrar or 7-Zip installed on our personal computers. They help combine multiple files/folders into a single file, which is more convenient to send, receive and manage. But did you notice that the zip or rar files produced by these software are usually smaller in size than the original files/folders, and wonder why? It turns out that these software use several Data Compression algorithms to reduce the file size, while still maintaining all of the information that the file contains. This is very useful, because not only it reduces the storage needed to store the file, but also the bandwidth required to transmit it.
In this problem, you are asked to implement a simple data compression algorithm which is very effective against strings with repetitive characters. This algorithm replaces every sub-string containing multiple identical consecutive characters with a copy of the character and a count of how many times it is repeated. For example, the string AAAAATTTTGGGGCCCCAAA, through the algorithm, is compressed to A5T4G4C4A3, which can now be interpreted as a sequence of five As, four Ts, four Gs, four Cs, and three As. Notice that the length of the output string is 10 which is only half of the input strings. In this case, we only need half the space to store the string, and half the internet bandwidth to send it.
Modify the function compress() in file hw4.py so that this function takes a string as input and returns the compressed string.
Example:
>>> compress( )
' '
>>> compress(a)
a1
>>> compress ( AAAAATTTTGGGGCCCCAAA )
A5T4G4C4A3
>>> compress ( ########## )
#10
>>> compress(zzz ZZ zZzZ)
'z3 1Z2 2z1Z1
For simplicity, you can assume that the input for this function is always a string which does not contain any numeric character.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
