Created
July 28, 2024 21:29
-
-
Save Shogun89/784c2a2bf4899e4c794288aed2001f7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import groupby | |
def run_length_encoding(s: str) -> str: | |
return ''.join(f"{len(list(group))}{key}" for key, group in groupby(s)) | |
s = "aaabbccccdeee" | |
grouped = groupby(s) | |
for key, group in grouped: | |
print(f"Key: {key}, Group: {list(group)}") | |
print(run_length_encoding(s)) |
Author
Shogun89
commented
Jul 28, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment