1def beginning(word):
 2    length = len(word)
 3
 4    if length % 3 == 2:
 5        last_index = length // 3 + 1
 6    else:
 7        last_index = length // 3
 8
 9    return word[:last_index]
10
11def middle(word):
12    length = len(word)
13    
14    if length % 3 == 0:
15        first_index = length // 3
16        last_index = 2 * length // 3
17    elif length % 3 == 2:
18        first_index = length // 3 + 1
19        last_index = 2 * length // 3
20    else:
21        first_index = length // 3
22        last_index = 2 * length // 3 + 1
23
24    return word[first_index:last_index]
25
26def end(word):
27    length = len(word)
28
29    if length % 3 == 1:
30        first_index = 2 * length // 3 + 1
31    else:
32        first_index = 2 * length // 3
33
34    return word[first_index:]
35
36def split_sentence(sentence):
37    words = sentence.split()
38    split_words = []
39
40    for word in words:
41        split_words.append((beginning(word), middle(word), end(word)))
42
43    return split_words
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
| t | 1 | '''dfsdf''' | t | ||
| 2 | |||||
| 3 | def beginning(word): | 1 | def beginning(word): | ||
| 4 | length = len(word) | 2 | length = len(word) | ||
| 5 | 3 | ||||
| 6 | if length % 3 == 2: | 4 | if length % 3 == 2: | ||
| 7 | last_index = length // 3 + 1 | 5 | last_index = length // 3 + 1 | ||
| 8 | else: | 6 | else: | ||
| 9 | last_index = length // 3 | 7 | last_index = length // 3 | ||
| 10 | 8 | ||||
| 11 | return word[:last_index] | 9 | return word[:last_index] | ||
| 12 | 10 | ||||
| 13 | def middle(word): | 11 | def middle(word): | ||
| 14 | length = len(word) | 12 | length = len(word) | ||
| 15 | 13 | ||||
| 16 | if length % 3 == 0: | 14 | if length % 3 == 0: | ||
| 17 | first_index = length // 3 | 15 | first_index = length // 3 | ||
| 18 | last_index = 2 * length // 3 | 16 | last_index = 2 * length // 3 | ||
| 19 | elif length % 3 == 2: | 17 | elif length % 3 == 2: | ||
| 20 | first_index = length // 3 + 1 | 18 | first_index = length // 3 + 1 | ||
| 21 | last_index = 2 * length // 3 | 19 | last_index = 2 * length // 3 | ||
| 22 | else: | 20 | else: | ||
| 23 | first_index = length // 3 | 21 | first_index = length // 3 | ||
| 24 | last_index = 2 * length // 3 + 1 | 22 | last_index = 2 * length // 3 + 1 | ||
| 25 | 23 | ||||
| 26 | return word[first_index:last_index] | 24 | return word[first_index:last_index] | ||
| 27 | 25 | ||||
| 28 | def end(word): | 26 | def end(word): | ||
| 29 | length = len(word) | 27 | length = len(word) | ||
| 30 | 28 | ||||
| 31 | if length % 3 == 1: | 29 | if length % 3 == 1: | ||
| 32 | first_index = 2 * length // 3 + 1 | 30 | first_index = 2 * length // 3 + 1 | ||
| 33 | else: | 31 | else: | ||
| 34 | first_index = 2 * length // 3 | 32 | first_index = 2 * length // 3 | ||
| 35 | 33 | ||||
| 36 | return word[first_index:] | 34 | return word[first_index:] | ||
| 37 | 35 | ||||
| 38 | def split_sentence(sentence): | 36 | def split_sentence(sentence): | ||
| 39 | words = sentence.split() | 37 | words = sentence.split() | ||
| 40 | split_words = [] | 38 | split_words = [] | ||
| 41 | 39 | ||||
| 42 | for word in words: | 40 | for word in words: | ||
| 43 | split_words.append((beginning(word), middle(word), end(word))) | 41 | split_words.append((beginning(word), middle(word), end(word))) | ||
| 44 | 42 | ||||
| 45 | return split_words | 43 | return split_words | 
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 
 | 
 | |||||||||
| n | n | 1 | '''dfsdf''' | ||
| 2 | |||||
| 1 | def beginning(word): | 3 | def beginning(word): | ||
| 2 | length = len(word) | 4 | length = len(word) | ||
| 3 | 5 | ||||
| n | 4 | if length % 3 == 0: | n | ||
| 5 | last_index = length // 3 | ||||
| 6 | elif length % 3 == 2: | 6 | if length % 3 == 2: | ||
| 7 | last_index = length // 3 + 1 | 7 | last_index = length // 3 + 1 | ||
| 8 | else: | 8 | else: | ||
| 9 | last_index = length // 3 | 9 | last_index = length // 3 | ||
| 10 | 10 | ||||
| 11 | return word[:last_index] | 11 | return word[:last_index] | ||
| 12 | 12 | ||||
| 13 | def middle(word): | 13 | def middle(word): | ||
| 14 | length = len(word) | 14 | length = len(word) | ||
| 15 | 15 | ||||
| 16 | if length % 3 == 0: | 16 | if length % 3 == 0: | ||
| 17 | first_index = length // 3 | 17 | first_index = length // 3 | ||
| 18 | last_index = 2 * length // 3 | 18 | last_index = 2 * length // 3 | ||
| 19 | elif length % 3 == 2: | 19 | elif length % 3 == 2: | ||
| 20 | first_index = length // 3 + 1 | 20 | first_index = length // 3 + 1 | ||
| 21 | last_index = 2 * length // 3 | 21 | last_index = 2 * length // 3 | ||
| 22 | else: | 22 | else: | ||
| 23 | first_index = length // 3 | 23 | first_index = length // 3 | ||
| 24 | last_index = 2 * length // 3 + 1 | 24 | last_index = 2 * length // 3 + 1 | ||
| 25 | 25 | ||||
| 26 | return word[first_index:last_index] | 26 | return word[first_index:last_index] | ||
| 27 | 27 | ||||
| 28 | def end(word): | 28 | def end(word): | ||
| 29 | length = len(word) | 29 | length = len(word) | ||
| 30 | 30 | ||||
| n | 31 | if length % 3 == 0: | n | 31 | if length % 3 == 1: | 
| 32 | first_index = 2 * length // 3 + 1 | ||||
| 33 | else: | ||||
| 32 | first_index = 2 * length // 3 | 34 | first_index = 2 * length // 3 | ||
| t | 33 | elif length % 3 == 2: | t | ||
| 34 | first_index = 2 * length // 3 | ||||
| 35 | else: | ||||
| 36 | first_index = 2 * length // 3 + 1 | ||||
| 37 | 35 | ||||
| 38 | return word[first_index:] | 36 | return word[first_index:] | ||
| 39 | 37 | ||||
| 40 | def split_sentence(sentence): | 38 | def split_sentence(sentence): | ||
| 41 | words = sentence.split() | 39 | words = sentence.split() | ||
| 42 | split_words = [] | 40 | split_words = [] | ||
| 43 | 41 | ||||
| 44 | for word in words: | 42 | for word in words: | ||
| 45 | split_words.append((beginning(word), middle(word), end(word))) | 43 | split_words.append((beginning(word), middle(word), end(word))) | ||
| 46 | 44 | ||||
| 47 | return split_words | 45 | return split_words | 
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 
 | 
 | |||||||||
| f | 1 | def beginning(word): | f | 1 | def beginning(word): | 
| 2 | length = len(word) | 2 | length = len(word) | ||
| 3 | 3 | ||||
| 4 | if length % 3 == 0: | 4 | if length % 3 == 0: | ||
| 5 | last_index = length // 3 | 5 | last_index = length // 3 | ||
| 6 | elif length % 3 == 2: | 6 | elif length % 3 == 2: | ||
| 7 | last_index = length // 3 + 1 | 7 | last_index = length // 3 + 1 | ||
| 8 | else: | 8 | else: | ||
| 9 | last_index = length // 3 | 9 | last_index = length // 3 | ||
| 10 | 10 | ||||
| 11 | return word[:last_index] | 11 | return word[:last_index] | ||
| 12 | 12 | ||||
| 13 | def middle(word): | 13 | def middle(word): | ||
| 14 | length = len(word) | 14 | length = len(word) | ||
| 15 | 15 | ||||
| 16 | if length % 3 == 0: | 16 | if length % 3 == 0: | ||
| 17 | first_index = length // 3 | 17 | first_index = length // 3 | ||
| 18 | last_index = 2 * length // 3 | 18 | last_index = 2 * length // 3 | ||
| 19 | elif length % 3 == 2: | 19 | elif length % 3 == 2: | ||
| 20 | first_index = length // 3 + 1 | 20 | first_index = length // 3 + 1 | ||
| 21 | last_index = 2 * length // 3 | 21 | last_index = 2 * length // 3 | ||
| 22 | else: | 22 | else: | ||
| 23 | first_index = length // 3 | 23 | first_index = length // 3 | ||
| 24 | last_index = 2 * length // 3 + 1 | 24 | last_index = 2 * length // 3 + 1 | ||
| 25 | 25 | ||||
| 26 | return word[first_index:last_index] | 26 | return word[first_index:last_index] | ||
| 27 | 27 | ||||
| 28 | def end(word): | 28 | def end(word): | ||
| 29 | length = len(word) | 29 | length = len(word) | ||
| 30 | 30 | ||||
| 31 | if length % 3 == 0: | 31 | if length % 3 == 0: | ||
| 32 | first_index = 2 * length // 3 | 32 | first_index = 2 * length // 3 | ||
| 33 | elif length % 3 == 2: | 33 | elif length % 3 == 2: | ||
| 34 | first_index = 2 * length // 3 | 34 | first_index = 2 * length // 3 | ||
| 35 | else: | 35 | else: | ||
| 36 | first_index = 2 * length // 3 + 1 | 36 | first_index = 2 * length // 3 + 1 | ||
| 37 | 37 | ||||
| 38 | return word[first_index:] | 38 | return word[first_index:] | ||
| 39 | 39 | ||||
| 40 | def split_sentence(sentence): | 40 | def split_sentence(sentence): | ||
| 41 | words = sentence.split() | 41 | words = sentence.split() | ||
| 42 | split_words = [] | 42 | split_words = [] | ||
| 43 | 43 | ||||
| 44 | for word in words: | 44 | for word in words: | ||
| 45 | split_words.append((beginning(word), middle(word), end(word))) | 45 | split_words.append((beginning(word), middle(word), end(word))) | ||
| 46 | 46 | ||||
| 47 | return split_words | 47 | return split_words | ||
| t | 48 | t | |||
| 49 | print(split_sentence('Kазвам се Джон Сноу')) | 
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 
 | 
 | |||||||||