Question: python Write a function that takes a string, compress the string by replacing consecutive repeating characters with their count, and finally return the compressed string.

python
python Write a function that takes a string, compress the string by
replacing consecutive repeating characters with their count, and finally return the compressed

Write a function that takes a string, compress the string by replacing consecutive repeating characters with their count, and finally return the compressed string. if the input string is "aabbbcccddddd," the output will be "a2b3c3d5": The function protype is given below: def compress_str(input_str: str | None) -> str | None: pass Write a decompress function for the previous problem: def decompress_str(input_str: str | None) -> str | None: pass Sample Usage and Output: print(compress_str("aabbbcccddddd")) print(compress_str("abcd")) print(compress_str("")) print(compress_str(None)) a 2 b3c3d5 abcd None None print(decompress_str("ab2c3d4")) print(decompress_str("a2b2c3d4e")) print(decompress_str("abcd")) print(decompress_str("a2b2c3d4e")) print(decompress_str("abcd")) print(decompress_str("")) print(decompress_str(None)) abbcccdddd a abbcccdddde abcd None None

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!