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