Compress the String! - Python Solution

Author: Al-mamun Sarkar Date: 2020-03-26 09:46:35

Compress the String! - Python Solution. The following shows how to solve the HackerRank Compress the String! Python itertools problem.

Code:

import itertools

print(*[ ( len(list(g)), int(k) ) for k, g in itertools.groupby(input()) ])

 

Test Input:

1222311

Test  Output:

(1, 1) (3, 2) (1, 3) (2, 1)