diff --git a/Python/06. Itertools/005. Compress the String!.py b/Python/06. Itertools/005. Compress the String!.py index aa7c5de..094e5c6 100644 --- a/Python/06. Itertools/005. Compress the String!.py +++ b/Python/06. Itertools/005. Compress the String!.py @@ -1,8 +1,16 @@ -# Problem: https://www.hackerrank.com/challenges/compress-the-string/problem -# Score: 20 +from itertools import groupby +# Take input string +s = input() -from itertools import groupby +# Initialize an empty list to store the result +result = [] + +# Group the string using groupby +for digit, group in groupby(s): + count = len(list(group)) # Count how many times the digit repeats + result.append((count, int(digit))) # Add tuple to result list +# Print the result, unpacked +print(*result) -print(*[(len(list(c)), int(x)) for x, c in groupby(input())])