Compress the String! - Python Solution

Compress the String! - Python Solution

Instructor-svgAl-Mamun Sarkar
Mar 26 , 2020

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)
  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram