-->

Compress The String! Hackerrank Solution Python | Compress The String Hackerrank

compress the string hackerrank solution python | hackerrank compress the string easy way |string compression hackerrank solution python


 Hello Friends 

आज हम आपको Hacker Rank पर Compress The String का कंप्लीट सॉल्यूशन बताएंगे वह भी आसान भाषा में। तो दोस्तों चलिए जानते हैं सॉल्यूशन ।

Subscribe Our YouTube Channel :- Apna Hindi Tech


Problem: Compress The String! Hackerrank Solution Python


You are given a string S. Suppose a character 'c' occurs consecutively X times in the string. Replace these consecutive occurrences of the character 'c' with (X, c) in the string.

For a better understanding of the problem, check the explanation.

Input Format


A single line of input consisting of the string S.

Output Format


A single line of output consisting of the modified string.

Constraints


All the characters of S denote integers between 0 and 9.
1<=|s|<=10^4


Sample Input

1222311


Sample Output

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



Explanation


First, the character 1 occurs only once. It is replaced by (1,1). Then the character 2 occurs three times, and it is replaced by (3,2) and so on.

Also, note the single space within each compression and between the compressions.

Solution


from itertools import groupby

for i,j in groupby(input()):
    print(tuple([len(list(j)),int(i)]),end=' ')

    
#This Code is written by Apna Hindi Tech





DISCLAIMER

The above hole problem statement is given by hackerrank.com but the solution is generated by the Apna Hindi Tech authority if any of the query regarding this post or website fill the following contact form.





......Thank You......

यह भी पढ़ें

Post a Comment