1def outer_size(word_size):
2 o_size = word_size // 3
3 if word_size % 3 == 2:
4 o_size += 1
5 return o_size
6
7def middle_size(word_size):
8 m_size = word_size // 3
9 if word_size % 3 == 1:
10 m_size += 1
11 return m_size
12
13def beginning(word):
14 end = outer_size(len(word))
15 return word[:end]
16
17def middle(word):
18 start = outer_size(len(word))
19 end = start + middle_size(len(word))
20 return word[start:end]
21
22def end(word):
23 start = outer_size(len(word)) + middle_size(len(word))
24 return word[start:]
25
26def split_sentence(sentence):
27 spl_sentence = []
28 for word in sentence.split():
29 spl_word = (beginning(word), middle(word), end(word))
30 spl_sentence.append(spl_word)
31 return spl_sentence
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
Светлозар Стефанов
11.10.2023 14:41Благодаря за обратната връзка, ще оправя всичко, а относно beginning size и end size доста се чудих, но прецених накрая да ги отделя, за да може при евентуална промяна на логиката да са независими, но в конкретната задача май наистина е по-удачно да са на едно.
|
n | 1 | def outrer_size(word_size): | n | 1 | def outer_size(word_size): |
2 | o_size = word_size // 3 | 2 | o_size = word_size // 3 | ||
3 | if word_size % 3 == 2: | 3 | if word_size % 3 == 2: | ||
4 | o_size += 1 | 4 | o_size += 1 | ||
5 | return o_size | 5 | return o_size | ||
6 | 6 | ||||
7 | def middle_size(word_size): | 7 | def middle_size(word_size): | ||
8 | m_size = word_size // 3 | 8 | m_size = word_size // 3 | ||
9 | if word_size % 3 == 1: | 9 | if word_size % 3 == 1: | ||
10 | m_size += 1 | 10 | m_size += 1 | ||
11 | return m_size | 11 | return m_size | ||
12 | 12 | ||||
13 | def beginning(word): | 13 | def beginning(word): | ||
n | 14 | end = outrer_size(len(word)) | n | 14 | end = outer_size(len(word)) |
15 | return word[:end] | 15 | return word[:end] | ||
16 | 16 | ||||
17 | def middle(word): | 17 | def middle(word): | ||
n | 18 | start = outrer_size(len(word)) | n | 18 | start = outer_size(len(word)) |
19 | end = start + middle_size(len(word)) | 19 | end = start + middle_size(len(word)) | ||
20 | return word[start:end] | 20 | return word[start:end] | ||
21 | 21 | ||||
22 | def end(word): | 22 | def end(word): | ||
t | 23 | start = outrer_size(len(word)) + middle_size(len(word)) | t | 23 | start = outer_size(len(word)) + middle_size(len(word)) |
24 | return word[start:] | 24 | return word[start:] | ||
25 | 25 | ||||
26 | def split_sentence(sentence): | 26 | def split_sentence(sentence): | ||
27 | spl_sentence = [] | 27 | spl_sentence = [] | ||
28 | for word in sentence.split(): | 28 | for word in sentence.split(): | ||
29 | spl_word = (beginning(word), middle(word), end(word)) | 29 | spl_word = (beginning(word), middle(word), end(word)) | ||
30 | spl_sentence.append(spl_word) | 30 | spl_sentence.append(spl_word) | ||
31 | return spl_sentence | 31 | return spl_sentence |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
n | 1 | def beginning_size(word_size): | n | 1 | def outrer_size(word_size): |
2 | b_size = word_size // 3 | 2 | o_size = word_size // 3 | ||
3 | if word_size % 3 == 2: | 3 | if word_size % 3 == 2: | ||
n | 4 | b_size += 1 | n | 4 | o_size += 1 |
5 | return b_size | 5 | return o_size | ||
6 | 6 | ||||
7 | def middle_size(word_size): | 7 | def middle_size(word_size): | ||
8 | m_size = word_size // 3 | 8 | m_size = word_size // 3 | ||
9 | if word_size % 3 == 1: | 9 | if word_size % 3 == 1: | ||
10 | m_size += 1 | 10 | m_size += 1 | ||
11 | return m_size | 11 | return m_size | ||
12 | 12 | ||||
n | 13 | def end_size(word_size): | n | ||
14 | e_size = word_size // 3 | ||||
15 | if word_size % 3 == 2: | ||||
16 | e_size += 1 | ||||
17 | return e_size | ||||
18 | |||||
19 | def beginning(word): | 13 | def beginning(word): | ||
n | 20 | word_size = len(word) | n | 14 | end = outrer_size(len(word)) |
21 | start = 0 | ||||
22 | end = beginning_size(word_size) | ||||
23 | return word[start:end] | 15 | return word[:end] | ||
24 | 16 | ||||
25 | def middle(word): | 17 | def middle(word): | ||
n | 26 | word_size = len(word) | n | 18 | start = outrer_size(len(word)) |
27 | start = beginning_size(word_size) | ||||
28 | end = start + middle_size(word_size) | 19 | end = start + middle_size(len(word)) | ||
29 | return word[start:end] | 20 | return word[start:end] | ||
30 | 21 | ||||
31 | def end(word): | 22 | def end(word): | ||
n | 32 | word_size = len(word) | n | 23 | start = outrer_size(len(word)) + middle_size(len(word)) |
33 | start = beginning_size(word_size) + middle_size(word_size) | ||||
34 | end = start + end_size(word_size) | ||||
35 | return word[start:end] | 24 | return word[start:] | ||
36 | 25 | ||||
37 | def split_sentence(sentence): | 26 | def split_sentence(sentence): | ||
38 | spl_sentence = [] | 27 | spl_sentence = [] | ||
n | 39 | for word in sentence.split(" "): | n | 28 | for word in sentence.split(): |
40 | spl_word = (beginning(word), middle(word), end(word)) | 29 | spl_word = (beginning(word), middle(word), end(word)) | ||
41 | spl_sentence.append(spl_word) | 30 | spl_sentence.append(spl_word) | ||
42 | return spl_sentence | 31 | return spl_sentence | ||
t | 43 | t | |||
44 | #print("Perhaps you would all like to say good evening together?") | ||||
45 | #print(f"On Ith: {beginning("Good")}") | ||||
46 | #print(f"J Sm: {middle("Good")}") | ||||
47 | #print(f"O E: {end("Good")}") | ||||
48 | #print() | ||||
49 | #print(f"On Ith: {beginning("Evening!")}") | ||||
50 | #print(f"J Sm: {middle("Evening!")}") | ||||
51 | #print(f"O E: {end("Evening!")}") |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning_size(word_size): | f | 1 | def beginning_size(word_size): |
2 | b_size = word_size // 3 | 2 | b_size = word_size // 3 | ||
3 | if word_size % 3 == 2: | 3 | if word_size % 3 == 2: | ||
4 | b_size += 1 | 4 | b_size += 1 | ||
5 | return b_size | 5 | return b_size | ||
6 | 6 | ||||
7 | def middle_size(word_size): | 7 | def middle_size(word_size): | ||
8 | m_size = word_size // 3 | 8 | m_size = word_size // 3 | ||
9 | if word_size % 3 == 1: | 9 | if word_size % 3 == 1: | ||
10 | m_size += 1 | 10 | m_size += 1 | ||
11 | return m_size | 11 | return m_size | ||
12 | 12 | ||||
13 | def end_size(word_size): | 13 | def end_size(word_size): | ||
14 | e_size = word_size // 3 | 14 | e_size = word_size // 3 | ||
15 | if word_size % 3 == 2: | 15 | if word_size % 3 == 2: | ||
16 | e_size += 1 | 16 | e_size += 1 | ||
17 | return e_size | 17 | return e_size | ||
18 | 18 | ||||
19 | def beginning(word): | 19 | def beginning(word): | ||
20 | word_size = len(word) | 20 | word_size = len(word) | ||
21 | start = 0 | 21 | start = 0 | ||
22 | end = beginning_size(word_size) | 22 | end = beginning_size(word_size) | ||
23 | return word[start:end] | 23 | return word[start:end] | ||
24 | 24 | ||||
25 | def middle(word): | 25 | def middle(word): | ||
26 | word_size = len(word) | 26 | word_size = len(word) | ||
27 | start = beginning_size(word_size) | 27 | start = beginning_size(word_size) | ||
28 | end = start + middle_size(word_size) | 28 | end = start + middle_size(word_size) | ||
29 | return word[start:end] | 29 | return word[start:end] | ||
30 | 30 | ||||
31 | def end(word): | 31 | def end(word): | ||
32 | word_size = len(word) | 32 | word_size = len(word) | ||
33 | start = beginning_size(word_size) + middle_size(word_size) | 33 | start = beginning_size(word_size) + middle_size(word_size) | ||
34 | end = start + end_size(word_size) | 34 | end = start + end_size(word_size) | ||
35 | return word[start:end] | 35 | return word[start:end] | ||
36 | 36 | ||||
n | 37 | def split_sentance(sentance): | n | 37 | def split_sentence(sentence): |
38 | spl_sentance = [] | 38 | spl_sentence = [] | ||
39 | for word in sentance.split(" "): | 39 | for word in sentence.split(" "): | ||
40 | spl_word = (beginning(word), middle(word), end(word)) | 40 | spl_word = (beginning(word), middle(word), end(word)) | ||
t | 41 | spl_sentance.append(spl_word) | t | 41 | spl_sentence.append(spl_word) |
42 | return spl_sentance | 42 | return spl_sentence | ||
43 | 43 | ||||
44 | #print("Perhaps you would all like to say good evening together?") | 44 | #print("Perhaps you would all like to say good evening together?") | ||
45 | #print(f"On Ith: {beginning("Good")}") | 45 | #print(f"On Ith: {beginning("Good")}") | ||
46 | #print(f"J Sm: {middle("Good")}") | 46 | #print(f"J Sm: {middle("Good")}") | ||
47 | #print(f"O E: {end("Good")}") | 47 | #print(f"O E: {end("Good")}") | ||
48 | #print() | 48 | #print() | ||
49 | #print(f"On Ith: {beginning("Evening!")}") | 49 | #print(f"On Ith: {beginning("Evening!")}") | ||
50 | #print(f"J Sm: {middle("Evening!")}") | 50 | #print(f"J Sm: {middle("Evening!")}") | ||
51 | #print(f"O E: {end("Evening!")}") | 51 | #print(f"O E: {end("Evening!")}") |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|