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