Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started