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