回答編集履歴
4
テキスト修正
test
CHANGED
@@ -47,3 +47,45 @@
|
|
47
47
|
|
48
48
|
|
49
49
|
参考になれば幸いです。
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
## 追記
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
正規表現を使わず、forループで目的の文字列を得るコードを追記します。
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
```python
|
62
|
+
|
63
|
+
def f(text):
|
64
|
+
|
65
|
+
output = ''
|
66
|
+
|
67
|
+
buff = []
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
for i in range(len(text)+1):
|
72
|
+
|
73
|
+
ch = text[i] if i < len(text) else None
|
74
|
+
|
75
|
+
if len(buff) > 0 and buff[0] != ch:
|
76
|
+
|
77
|
+
output += f'{buff[0]}{len(buff)}'
|
78
|
+
|
79
|
+
buff.clear()
|
80
|
+
|
81
|
+
buff.append(ch)
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
return output
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
```
|
90
|
+
|
91
|
+
- **動作確認用Repl.it:** [repl.it/@jun68ykt/Q295152-2](https://repl.it/@jun68ykt/Q295152-2)
|
3
テキスト修正
test
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
print(f('jjffir')) # => 'j2f2i1r1'
|
28
28
|
|
29
|
-
print(f('kkkkrrYcccccbbXXpppppppppZZ')) # => 'k4r2
|
29
|
+
print(f('kkkkrrYcccccbbXXpppppppppZZ')) # => 'k4r2Y1c5b2X2p9Z2'
|
30
30
|
|
31
31
|
print(f('u')) # => 'u1'
|
32
32
|
|
2
テキスト修正
test
CHANGED
@@ -26,13 +26,17 @@
|
|
26
26
|
|
27
27
|
print(f('jjffir')) # => 'j2f2i1r1'
|
28
28
|
|
29
|
-
print(f('kkkkrrYcccccbbXXpppppppppZZ')) # => 'k4r2
|
29
|
+
print(f('kkkkrrYcccccbbXXpppppppppZZ')) # => 'k4r2y1c5b2X2p9z2'
|
30
30
|
|
31
31
|
print(f('u')) # => 'u1'
|
32
32
|
|
33
33
|
print(f('xxxxxxxxxxxxxxx')) # => 'x15'
|
34
34
|
|
35
|
+
print(f('abcd')) # => 'a1b1c1d1'
|
36
|
+
|
35
37
|
print(f('')) # => ''
|
38
|
+
|
39
|
+
|
36
40
|
|
37
41
|
```
|
38
42
|
|
1
テキスト修正
test
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
print(f('jjffir')) # => 'j2f2i1r1'
|
28
28
|
|
29
|
-
print(f('kkkkrrYcccccbbXXpppppppppZZ')) # => 'k4r2
|
29
|
+
print(f('kkkkrrYcccccbbXXpppppppppZZ')) # => 'k4r2Y1c5b2X2p9Z2'
|
30
30
|
|
31
31
|
print(f('u')) # => 'u1'
|
32
32
|
|