Skip to content

Instantly share code, notes, and snippets.

@Shogun89
Created July 28, 2024 21:29
Show Gist options
  • Save Shogun89/784c2a2bf4899e4c794288aed2001f7f to your computer and use it in GitHub Desktop.
Save Shogun89/784c2a2bf4899e4c794288aed2001f7f to your computer and use it in GitHub Desktop.
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))
@Shogun89
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment