-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path025_Split Strings.py
59 lines (41 loc) · 1.16 KB
/
025_Split Strings.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
Codewars Coding Challenge
Split Strings
DESCRIPTION:
Complete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore ('_').
Examples:
* 'abc' => ['ab', 'c_']
* 'abcdef' => ['ab', 'cd', 'ef']
https://www.codewars.com/kata/515de9ae9dcfc28eb6000001/train/python
"""
# My Solution
def solution(s):
pairs = []
for i in range(0, len(s), 2):
pair = s[i:i+2]
if len(pair) < 2:
pair += "_"
pairs.append(pair)
return pairs
print(solution("abcdefg"))
print(solution("abcdef"))
"""
Sample Test
import codewars_test as test
from solution import *
@test.describe("Fixed Tests")
def fixed_tests():
@test.it('Basic Test Cases')
def basic_test_cases():
tests = (
("asdfadsf", ['as', 'df', 'ad', 'sf']),
("asdfads", ['as', 'df', 'ad', 's_']),
("", []),
("x", ["x_"]),
)
for inp, exp in tests:
test.assert_equals(solution(inp), exp)
"""
"""
Perfect Solution From Codewars
"""