You are viewing a single comment's thread. Return to all comments →
from itertools import groupby
def run_length_encoding(s): encoded_parts = [] for key, group in groupby(s): count = len(list(group)) encoded_parts.append(f'({count}, {key})') return ' '.join(encoded_parts)
input_string = input() output_string = run_length_encoding(input_string) print(output_string)
Seems like cookies are disabled on this browser, please enable them to open this website
Compress the String!
You are viewing a single comment's thread. Return to all comments →
from itertools import groupby
def run_length_encoding(s): encoded_parts = [] for key, group in groupby(s): count = len(list(group)) encoded_parts.append(f'({count}, {key})') return ' '.join(encoded_parts)
input_string = input() output_string = run_length_encoding(input_string) print(output_string)