HackerRank Python - Compress the String




In this task, we would like for you to appreciate the usefulness of the groupby() function of itertools . To read more about this function, Check this out .



  1. # Enter your code here. Read input from STDIN. Print output to STDOUT
  2. from itertools import groupby
  3. for key, group in groupby(input()):
  4. print((len(list(group)), int(key)), end=' ')




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube