suneelvarma Posted on Sep 16, 2019 Problem in Python #python input=111115 output=5115 how to solve this problem in python? Top comments (1) Subscribe Personal Trusted User Create template Templates let you quickly answer FAQs or store snippets for re-use. Submit Preview Dismiss Collapse Expand orenovadia orenovadia orenovadia Follow Joined Jun 23, 2019 • Sep 18 '19 Dropdown menu Copy link Hide 1) Converting the number to a string 2) Using itertools.groupby to group each subsequent repeating digit 3) Concatenating each grouped digit with the size of its group 4) Concatenating the whole thing to one string In [16]: ''.join(str(len(list(group))) + digit for digit, group in itertools.groupby(str(111115))) Out[16]: '5115' (I interpreted the question so that the expected output for 151 is 111511 and not 2115). Code of Conduct • Report abuse Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse
Top comments (1)
1) Converting the number to a string
2) Using
itertools.groupbyto group each subsequent repeating digit3) Concatenating each grouped digit with the size of its group
4) Concatenating the whole thing to one string
(I interpreted the question so that the expected output for 151 is 111511 and not 2115).