You are viewing a single comment's thread. Return to all comments →
Logic without using itertools.groupby() as:-
def groupby_custom(s): l_group = [] l_key = [] count = 1 for ind, i in enumerate(s): if ind+1 < len(s) and s[ind+1] == s[ind]: count += 1 else: l_group.append([i] * count) l_key.append(i) count = 1 return zip(l_key, l_group) s = list(input()) for k, group in groupby_custom(s): print(f"({len(list(group))}, {k})", end=" ")
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 →
Logic without using itertools.groupby() as:-