1def beginning(word):
2 end = len(word)//3 if len(word) % 3 < 2 else len(word)//3 + 1
3 return word[0:end]
4
5def middle(word):
6 start = len(word)//3 + 1 if len(word) % 3 == 2 else len(word)//3
7 end = 2 * len(word)//3 + 1 if len(word) % 3 == 1 else 2 * len(word)//3
8 return word[start:end]
9
10def end(word):
11 lenght = len(word)//3 + 1 if len(word) % 3 == 2 else len(word)//3
12 return '' if lenght == 0 else word[-lenght:]
13
14def split_sentence(sentence):
15 words = sentence.split(' ')
16 result = []
17 for word in words:
18 current_tuple = beginning(word), middle(word), end(word)
19 result.append(current_tuple)
20 return result
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
n | 2 | end = len(word)//3 if (len(word) % 3) < 2 else len(word)//3 + 1 | n | 2 | end = len(word)//3 if len(word) % 3 < 2 else len(word)//3 + 1 |
3 | return(word[0:end]) | 3 | return word[0:end] | ||
4 | 4 | ||||
5 | def middle(word): | 5 | def middle(word): | ||
n | 6 | start = len(word)//3 + 1 if (len(word) % 3) == 2 else len(word)//3 | n | 6 | start = len(word)//3 + 1 if len(word) % 3 == 2 else len(word)//3 |
7 | end = 2 * len(word)//3 + 1 if (len(word) % 3) == 1 else 2 * len(word)//3 | 7 | end = 2 * len(word)//3 + 1 if len(word) % 3 == 1 else 2 * len(word)//3 | ||
8 | return(word[start:end]) | 8 | return word[start:end] | ||
9 | 9 | ||||
10 | def end(word): | 10 | def end(word): | ||
n | 11 | lenght = len(word)//3 + 1 if (len(word) % 3) == 2 else len(word)//3 | n | 11 | lenght = len(word)//3 + 1 if len(word) % 3 == 2 else len(word)//3 |
12 | return('' if lenght == 0 else word[-lenght:]) | 12 | return '' if lenght == 0 else word[-lenght:] | ||
13 | 13 | ||||
14 | def split_sentence(sentence): | 14 | def split_sentence(sentence): | ||
15 | words = sentence.split(' ') | 15 | words = sentence.split(' ') | ||
16 | result = [] | 16 | result = [] | ||
17 | for word in words: | 17 | for word in words: | ||
t | 18 | currentTuple = (beginning(word), middle(word), end(word)) | t | 18 | current_tuple = beginning(word), middle(word), end(word) |
19 | result.append(currentTuple) | 19 | result.append(current_tuple) | ||
20 | return result | 20 | return result |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|