1def measure_len(word):
2 word_len = len(word)
3 split_len = word_len // 3
4 remainder = word_len % 3
5 return split_len, remainder
6
7
8def beginning(word):
9 split_len, remainder = measure_len(word)
10 if remainder == 2:
11 return word[:split_len + 1]
12 else:
13 return word[:split_len]
14
15
16def middle(word):
17 split_len, remainder = measure_len(word)
18 if remainder == 0:
19 return word[split_len:split_len * 2]
20 elif remainder == 2:
21 return word[split_len + 1:split_len * 2 + 1]
22 else:
23 return word[split_len:split_len * 2 + 1]
24
25
26def end(word):
27 split_len, remainder = measure_len(word)
28 doubled_split_len = split_len * 2
29 if remainder == 0:
30 return word[doubled_split_len:]
31 else:
32 return word[doubled_split_len + 1:]
33
34
35def split_sentence(sentence):
36 result = []
37 words = sentence.split()
38
39 for word in words:
40 beg_part = beginning(word)
41 mid_part = middle(word)
42 end_part = end(word)
43 result.append((beg_part, mid_part, end_part))
44
45 return result
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
Георги Кунчев
17.10.2023 15:59Виждам, че току що качи нова версия и е възможно да пропуснеш коментарите, които оставих на старото.
Виж ги по-долу в историята.
|
n | 1 | def beginning(word): | n | 1 | def measure_len(word): |
2 | word_len = len(word) | 2 | word_len = len(word) | ||
3 | split_len = word_len // 3 | 3 | split_len = word_len // 3 | ||
4 | remainder = word_len % 3 | 4 | remainder = word_len % 3 | ||
n | 5 | if remainder == 0: | n | 5 | return split_len, remainder |
6 | return word[0:split_len] | 6 | |||
7 | |||||
8 | def beginning(word): | ||||
9 | split_len, remainder = measure_len(word) | ||||
7 | elif remainder == 2: | 10 | if remainder == 2: | ||
8 | return word[0:split_len + 1] | 11 | return word[:split_len + 1] | ||
9 | elif remainder == 1: | 12 | else: | ||
10 | return word[0:split_len] | 13 | return word[:split_len] | ||
11 | 14 | ||||
12 | 15 | ||||
13 | def middle(word): | 16 | def middle(word): | ||
n | 14 | word_len = len(word) | n | 17 | split_len, remainder = measure_len(word) |
15 | split_len = word_len // 3 | ||||
16 | remainder = word_len % 3 | ||||
17 | if remainder == 0: | 18 | if remainder == 0: | ||
18 | return word[split_len:split_len * 2] | 19 | return word[split_len:split_len * 2] | ||
19 | elif remainder == 2: | 20 | elif remainder == 2: | ||
20 | return word[split_len + 1:split_len * 2 + 1] | 21 | return word[split_len + 1:split_len * 2 + 1] | ||
n | 21 | elif remainder == 1: | n | 22 | else: |
22 | return word[split_len:split_len * 2 + 1] | 23 | return word[split_len:split_len * 2 + 1] | ||
23 | 24 | ||||
24 | 25 | ||||
25 | def end(word): | 26 | def end(word): | ||
n | 26 | word_len = len(word) | n | 27 | split_len, remainder = measure_len(word) |
27 | split_len = word_len // 3 | ||||
28 | remainder = word_len % 3 | ||||
29 | doubled_split_len = split_len * 2 | 28 | doubled_split_len = split_len * 2 | ||
30 | if remainder == 0: | 29 | if remainder == 0: | ||
n | 31 | return word[doubled_split_len::] | n | 30 | return word[doubled_split_len:] |
32 | elif remainder == 2: | 31 | else: | ||
33 | return word[doubled_split_len + 1::] | 32 | return word[doubled_split_len + 1:] | ||
34 | elif remainder == 1: | ||||
35 | return word[doubled_split_len + 1::] | ||||
36 | 33 | ||||
37 | 34 | ||||
38 | def split_sentence(sentence): | 35 | def split_sentence(sentence): | ||
39 | result = [] | 36 | result = [] | ||
n | 40 | words = sentence.split(' ') | n | 37 | words = sentence.split() |
41 | 38 | ||||
42 | for word in words: | 39 | for word in words: | ||
43 | beg_part = beginning(word) | 40 | beg_part = beginning(word) | ||
44 | mid_part = middle(word) | 41 | mid_part = middle(word) | ||
45 | end_part = end(word) | 42 | end_part = end(word) | ||
n | 46 | new_word = (beg_part, mid_part, end_part) | n | 43 | result.append((beg_part, mid_part, end_part)) |
47 | result.append(new_word) | ||||
48 | 44 | ||||
49 | return result | 45 | return result | ||
t | t | 46 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | word_len = len(word) | 2 | word_len = len(word) | ||
3 | split_len = word_len // 3 | 3 | split_len = word_len // 3 | ||
n | 4 | if word_len % 3 == 0: | n | 4 | remainder = word_len % 3 |
5 | if remainder == 0: | ||||
5 | return word[0:split_len] | 6 | return word[0:split_len] | ||
n | 6 | elif word_len % 3 == 2: | n | 7 | elif remainder == 2: |
7 | return word[0:split_len + 1] | 8 | return word[0:split_len + 1] | ||
n | 8 | elif word_len % 3 == 1: | n | 9 | elif remainder == 1: |
9 | return word[0:split_len] | 10 | return word[0:split_len] | ||
10 | 11 | ||||
11 | 12 | ||||
12 | def middle(word): | 13 | def middle(word): | ||
13 | word_len = len(word) | 14 | word_len = len(word) | ||
14 | split_len = word_len // 3 | 15 | split_len = word_len // 3 | ||
n | 15 | if word_len % 3 == 0: | n | 16 | remainder = word_len % 3 |
17 | if remainder == 0: | ||||
16 | return word[split_len:split_len * 2] | 18 | return word[split_len:split_len * 2] | ||
n | 17 | elif word_len % 3 == 2: | n | 19 | elif remainder == 2: |
18 | return word[split_len + 1:split_len * 2 + 1] | 20 | return word[split_len + 1:split_len * 2 + 1] | ||
n | 19 | elif word_len % 3 == 1: | n | 21 | elif remainder == 1: |
20 | return word[split_len:split_len * 2 + 1] | 22 | return word[split_len:split_len * 2 + 1] | ||
21 | 23 | ||||
22 | 24 | ||||
23 | def end(word): | 25 | def end(word): | ||
24 | word_len = len(word) | 26 | word_len = len(word) | ||
25 | split_len = word_len // 3 | 27 | split_len = word_len // 3 | ||
n | n | 28 | remainder = word_len % 3 | ||
26 | doubled_split_len = split_len * 2 | 29 | doubled_split_len = split_len * 2 | ||
n | 27 | if word_len % 3 == 0: | n | 30 | if remainder == 0: |
28 | return word[doubled_split_len::] | 31 | return word[doubled_split_len::] | ||
n | 29 | elif word_len % 3 == 2: | n | 32 | elif remainder == 2: |
30 | return word[doubled_split_len + 1::] | 33 | return word[doubled_split_len + 1::] | ||
n | 31 | elif word_len % 3 == 1: | n | 34 | elif remainder == 1: |
32 | return word[doubled_split_len + 1::] | 35 | return word[doubled_split_len + 1::] | ||
33 | 36 | ||||
34 | 37 | ||||
35 | def split_sentence(sentence): | 38 | def split_sentence(sentence): | ||
36 | result = [] | 39 | result = [] | ||
37 | words = sentence.split(' ') | 40 | words = sentence.split(' ') | ||
t | 38 | t | 41 | ||
39 | for word in words: | 42 | for word in words: | ||
40 | beg_part = beginning(word) | 43 | beg_part = beginning(word) | ||
41 | mid_part = middle(word) | 44 | mid_part = middle(word) | ||
42 | end_part = end(word) | 45 | end_part = end(word) | ||
43 | new_word = (beg_part, mid_part, end_part) | 46 | new_word = (beg_part, mid_part, end_part) | ||
44 | result.append(new_word) | 47 | result.append(new_word) | ||
45 | 48 | ||||
46 | return result | 49 | return result |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|