-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompress_the_String!.py
43 lines (28 loc) · 1.16 KB
/
Compress_the_String!.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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 .
# You are given a string . Suppose a character '' occurs consecutively times in the string. Replace these consecutive occurrences of the character '' with in the string.
# For a better understanding of the problem, check the explanation.
# Input Format
# A single line of input consisting of the string .
# Output Format
# A single line of output consisting of the modified string.
# Constraints
# All the characters of denote integers between and .
# Sample Input
# 1222311
# Sample Output
# (1, 1) (3, 2) (1, 3) (2, 1)
# Explanation
# First, the character occurs only once. It is replaced by . Then the character occurs three times, and it is replaced by and so on.
# Also, note the single space within each compression and between the compressions.
# Enter your code here. Read input from STDIN. Print output to STDOUT
s = input()
bef = s[0]
cou = 0
for i in s:
if i == bef:
cou+=1
else:
print((cou,int(bef)),end=" ")
bef = i
cou=1
print((cou,int(bef)),end=" ")