Skip to content

Commit 12362a7

Browse files
committed
fix issue with a10
1 parent bc8ccb3 commit 12362a7

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Python/chapter01/1.6 - String Compression/miguel_1.6_sol.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def str_compression(s: str) -> str:
2929
if c == prev_char:
3030
count += 1
3131
continue
32-
compressed.append('{}{}'.format(prev_char, str(count)[0]))
32+
compressed.append('{}{}'.format(prev_char, str(count)))
3333
prev_char = c
3434
count = 1
3535
# clean up: last character count
36-
compressed.append('{}{}'.format(prev_char, str(count)[0]))
36+
compressed.append('{}{}'.format(prev_char, str(count)))
3737
compressed = ''.join(compressed)
3838
if len(compressed) >= len(s):
3939
return s
@@ -48,7 +48,8 @@ def test_string_compression(self):
4848
('aabbccdd', 'aabbccdd'),
4949
('', ''),
5050
('c', 'c'),
51-
('aaAAccCCCCC', 'a2A2c2C5')
51+
('aaAAccCCCCC', 'a2A2c2C5'),
52+
('aaaaaaaaaa', 'a10')
5253
]
5354
for s, expected in cases:
5455
self.assertEqual(str_compression(s), expected, msg=(s, expected))

0 commit comments

Comments
 (0)