In this problem we just need to use itertools groupby() function to groupings categorize the things the main issue is that we need consecutive string character to with there X times with char in tuples group
this just naive solution you can do more better to use the lambada, map and other function with it
Here we taking string input which is numbers with consecutive numbers some we need there count on concessive steps and grouping them through group by and then again print them with Times they occur as tuples
Problem:https://www.hackerrank.com/challenges/compress-the-string/problem?isFullScreen=true
Code:
from itertools import groupby
S = input()
# groupby will group consecutive characters
for key, group in groupby(S):
group_list = list(group)
print(f"({len(group_list)}, {key})", end=" ")
