Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def decompress_string(compressed_str):
- decompressed_str = ""
- i = 0
- while i < len(compressed_str):
- char = compressed_str[i]
- i += 1
- count = 0
- while i < len(compressed_str) and compressed_str[i].isdigit():
- count = count * 10 + int(compressed_str[i])
- i += 1
- decompressed_str += char * (count if count > 0 else 1)
- return decompressed_str
- # Example usage
- compressed_str = "a3b2c"
- decompressed_str = decompress_string(compressed_str)
- print(decompressed_str) # Output: aaabbc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement