1def beginning(word):
2 length = len(word) // 3
3
4 if len(word) % 3 == 2:
5 length +=1
6
7 return word[:length]
8
9
10def middle(word):
11 length = len(word) // 3
12 end = 2 * length
13
14 if len(word) % 3 == 1:
15 end += 1
16 elif len(word) % 3 == 2:
17 length += 1
18 end += 1
19
20 return word[length:end]
21
22
23def end(word):
24 start = len(word) - len(word) // 3
25
26 if len(word) % 3 == 2:
27 start -=1
28
29 return word[start:]
30
31
32def split_sentence(sentence):
33 words = sentence.split()
34
35 result = []
36 for word in words:
37 result.append((beginning(word), middle(word), end(word)))
38 return result
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
| f | 1 | def beginning(word): | f | 1 | def beginning(word): |
| 2 | length = len(word) // 3 | 2 | length = len(word) // 3 | ||
| n | 3 | start = 0 | n | ||
| 4 | end = start + length | ||||
| 5 | 3 | ||||
| 6 | if len(word) % 3 == 2: | 4 | if len(word) % 3 == 2: | ||
| n | 7 | length += 1 | n | 5 | length +=1 |
| 8 | end +=1 | ||||
| 9 | 6 | ||||
| n | 10 | return word[start:end] | n | 7 | return word[:length] |
| 11 | 8 | ||||
| 12 | 9 | ||||
| 13 | def middle(word): | 10 | def middle(word): | ||
| 14 | length = len(word) // 3 | 11 | length = len(word) // 3 | ||
| n | 15 | start = length | n | ||
| 16 | end = start + length | 12 | end = 2 * length | ||
| 17 | 13 | ||||
| 18 | if len(word) % 3 == 1: | 14 | if len(word) % 3 == 1: | ||
| 19 | end += 1 | 15 | end += 1 | ||
| 20 | elif len(word) % 3 == 2: | 16 | elif len(word) % 3 == 2: | ||
| n | 21 | start += 1 | n | 17 | length += 1 |
| 22 | end += 1 | 18 | end += 1 | ||
| 23 | 19 | ||||
| n | 24 | return word[start:end] | n | 20 | return word[length:end] |
| 25 | 21 | ||||
| 26 | 22 | ||||
| 27 | def end(word): | 23 | def end(word): | ||
| n | 28 | length = len(word) // 3 | n | 24 | start = len(word) - len(word) // 3 |
| 29 | end = len(word) | ||||
| 30 | start = end - length | ||||
| 31 | 25 | ||||
| 32 | if len(word) % 3 == 2: | 26 | if len(word) % 3 == 2: | ||
| 33 | start -=1 | 27 | start -=1 | ||
| 34 | 28 | ||||
| t | 35 | return word[start:end] | t | 29 | return word[start:] |
| 36 | 30 | ||||
| 37 | 31 | ||||
| 38 | def split_sentence(sentence): | 32 | def split_sentence(sentence): | ||
| 39 | words = sentence.split() | 33 | words = sentence.split() | ||
| 40 | 34 | ||||
| 41 | result = [] | 35 | result = [] | ||
| 42 | for word in words: | 36 | for word in words: | ||
| 43 | result.append((beginning(word), middle(word), end(word))) | 37 | result.append((beginning(word), middle(word), end(word))) | ||
| 44 | return result | 38 | return result |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| f | 1 | def beginning(word): | f | 1 | def beginning(word): |
| 2 | length = len(word) // 3 | 2 | length = len(word) // 3 | ||
| 3 | start = 0 | 3 | start = 0 | ||
| 4 | end = start + length | 4 | end = start + length | ||
| 5 | 5 | ||||
| n | 6 | if(len(word) % 3 == 2): | n | 6 | if len(word) % 3 == 2: |
| 7 | length += 1 | 7 | length += 1 | ||
| 8 | end +=1 | 8 | end +=1 | ||
| 9 | 9 | ||||
| 10 | return word[start:end] | 10 | return word[start:end] | ||
| 11 | 11 | ||||
| 12 | 12 | ||||
| 13 | def middle(word): | 13 | def middle(word): | ||
| 14 | length = len(word) // 3 | 14 | length = len(word) // 3 | ||
| 15 | start = length | 15 | start = length | ||
| 16 | end = start + length | 16 | end = start + length | ||
| 17 | 17 | ||||
| n | 18 | if(len(word) % 3 == 1): | n | 18 | if len(word) % 3 == 1: |
| 19 | end += 1 | 19 | end += 1 | ||
| 20 | elif(len(word) % 3 == 2): | 20 | elif len(word) % 3 == 2: | ||
| 21 | start += 1 | 21 | start += 1 | ||
| 22 | end += 1 | 22 | end += 1 | ||
| 23 | 23 | ||||
| 24 | return word[start:end] | 24 | return word[start:end] | ||
| 25 | 25 | ||||
| 26 | 26 | ||||
| 27 | def end(word): | 27 | def end(word): | ||
| 28 | length = len(word) // 3 | 28 | length = len(word) // 3 | ||
| 29 | end = len(word) | 29 | end = len(word) | ||
| 30 | start = end - length | 30 | start = end - length | ||
| 31 | 31 | ||||
| t | 32 | if(len(word) % 3 == 2): | t | 32 | if len(word) % 3 == 2: |
| 33 | start -=1 | 33 | start -=1 | ||
| 34 | 34 | ||||
| 35 | return word[start:end] | 35 | return word[start:end] | ||
| 36 | 36 | ||||
| 37 | 37 | ||||
| 38 | def split_sentence(sentence): | 38 | def split_sentence(sentence): | ||
| 39 | words = sentence.split() | 39 | words = sentence.split() | ||
| 40 | 40 | ||||
| 41 | result = [] | 41 | result = [] | ||
| 42 | for word in words: | 42 | for word in words: | ||
| 43 | result.append((beginning(word), middle(word), end(word))) | 43 | result.append((beginning(word), middle(word), end(word))) | ||
| 44 | return result | 44 | return result |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||