Compress the String!

  • + 0 comments
    • Nice, a list comprehension with an input and print function (bad habbit). I think it's better to add meaningful variable names, at least considering you are showcasing your code for everyone to see.

    Here for example, you can add #comments to explain what your doing a different steps.

    from itertools import groupby
    sequence = input()
    groups = [(len(list(c)), int(s)) for s, c in groupby(sequence)]
    print(*groups)  # unpack the list of tuple pairs and print.