1def beginning(word):
2 length = len(word)
3 upper_bound = length // 3
4 if length % 3 in (0,1):
5 return word[:upper_bound]
6 elif length % 3 == 2:
7 return word[:(upper_bound + 1)]
8
9def middle(word):
10 length = len(word)
11 upper_bound = length // 3
12 if length % 3 == 0:
13 return word[upper_bound:(upper_bound*2)]
14 elif length % 3 == 2:
15 return word[upper_bound+1:(2*upper_bound + 1)]
16 elif length % 3 == 1:
17 return word[upper_bound:(2*upper_bound + 1)]
18
19def end(word):
20 length = len(word)
21 upper_bound = length // 3
22 if length % 3 == 0:
23 return word[(upper_bound*2):]
24 elif length % 3 == 2:
25 return word[(2*upper_bound + 1):]
26 elif length % 3 == 1:
27 return word[(2 * upper_bound + 1):]
28
29def split_word(word):
30 return beginning(word), middle(word), end(word)
31
32def split_sentence(sentence):
33 my_list = []
34 list_from_sentence = sentence.split()
35 for word in list_from_sentence:
36 my_list.append(split_word(word))
37 return my_list
............
----------------------------------------------------------------------
Ran 12 tests in 0.001s
OK
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | length = len(word) | 2 | length = len(word) | ||
3 | upper_bound = length // 3 | 3 | upper_bound = length // 3 | ||
4 | if length % 3 in (0,1): | 4 | if length % 3 in (0,1): | ||
5 | return word[:upper_bound] | 5 | return word[:upper_bound] | ||
6 | elif length % 3 == 2: | 6 | elif length % 3 == 2: | ||
7 | return word[:(upper_bound + 1)] | 7 | return word[:(upper_bound + 1)] | ||
8 | 8 | ||||
9 | def middle(word): | 9 | def middle(word): | ||
10 | length = len(word) | 10 | length = len(word) | ||
11 | upper_bound = length // 3 | 11 | upper_bound = length // 3 | ||
12 | if length % 3 == 0: | 12 | if length % 3 == 0: | ||
13 | return word[upper_bound:(upper_bound*2)] | 13 | return word[upper_bound:(upper_bound*2)] | ||
14 | elif length % 3 == 2: | 14 | elif length % 3 == 2: | ||
15 | return word[upper_bound+1:(2*upper_bound + 1)] | 15 | return word[upper_bound+1:(2*upper_bound + 1)] | ||
16 | elif length % 3 == 1: | 16 | elif length % 3 == 1: | ||
17 | return word[upper_bound:(2*upper_bound + 1)] | 17 | return word[upper_bound:(2*upper_bound + 1)] | ||
18 | 18 | ||||
19 | def end(word): | 19 | def end(word): | ||
20 | length = len(word) | 20 | length = len(word) | ||
21 | upper_bound = length // 3 | 21 | upper_bound = length // 3 | ||
22 | if length % 3 == 0: | 22 | if length % 3 == 0: | ||
23 | return word[(upper_bound*2):] | 23 | return word[(upper_bound*2):] | ||
24 | elif length % 3 == 2: | 24 | elif length % 3 == 2: | ||
25 | return word[(2*upper_bound + 1):] | 25 | return word[(2*upper_bound + 1):] | ||
26 | elif length % 3 == 1: | 26 | elif length % 3 == 1: | ||
27 | return word[(2 * upper_bound + 1):] | 27 | return word[(2 * upper_bound + 1):] | ||
28 | 28 | ||||
29 | def split_word(word): | 29 | def split_word(word): | ||
30 | return beginning(word), middle(word), end(word) | 30 | return beginning(word), middle(word), end(word) | ||
31 | 31 | ||||
32 | def split_sentence(sentence): | 32 | def split_sentence(sentence): | ||
33 | my_list = [] | 33 | my_list = [] | ||
34 | list_from_sentence = sentence.split() | 34 | list_from_sentence = sentence.split() | ||
35 | for word in list_from_sentence: | 35 | for word in list_from_sentence: | ||
36 | my_list.append(split_word(word)) | 36 | my_list.append(split_word(word)) | ||
37 | return my_list | 37 | return my_list | ||
t | 38 | t | |||
39 | print(split_sentence('Kазвам се Джон Сноу')) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | length = len(word) | 2 | length = len(word) | ||
3 | upper_bound = length // 3 | 3 | upper_bound = length // 3 | ||
n | 4 | if length % 3 == 0 or length % 3 == 1: | n | 4 | if length % 3 in (0,1): |
5 | return word[:upper_bound] | 5 | return word[:upper_bound] | ||
6 | elif length % 3 == 2: | 6 | elif length % 3 == 2: | ||
7 | return word[:(upper_bound + 1)] | 7 | return word[:(upper_bound + 1)] | ||
8 | 8 | ||||
9 | def middle(word): | 9 | def middle(word): | ||
10 | length = len(word) | 10 | length = len(word) | ||
11 | upper_bound = length // 3 | 11 | upper_bound = length // 3 | ||
12 | if length % 3 == 0: | 12 | if length % 3 == 0: | ||
13 | return word[upper_bound:(upper_bound*2)] | 13 | return word[upper_bound:(upper_bound*2)] | ||
14 | elif length % 3 == 2: | 14 | elif length % 3 == 2: | ||
15 | return word[upper_bound+1:(2*upper_bound + 1)] | 15 | return word[upper_bound+1:(2*upper_bound + 1)] | ||
16 | elif length % 3 == 1: | 16 | elif length % 3 == 1: | ||
17 | return word[upper_bound:(2*upper_bound + 1)] | 17 | return word[upper_bound:(2*upper_bound + 1)] | ||
18 | 18 | ||||
19 | def end(word): | 19 | def end(word): | ||
20 | length = len(word) | 20 | length = len(word) | ||
21 | upper_bound = length // 3 | 21 | upper_bound = length // 3 | ||
22 | if length % 3 == 0: | 22 | if length % 3 == 0: | ||
23 | return word[(upper_bound*2):] | 23 | return word[(upper_bound*2):] | ||
24 | elif length % 3 == 2: | 24 | elif length % 3 == 2: | ||
25 | return word[(2*upper_bound + 1):] | 25 | return word[(2*upper_bound + 1):] | ||
26 | elif length % 3 == 1: | 26 | elif length % 3 == 1: | ||
27 | return word[(2 * upper_bound + 1):] | 27 | return word[(2 * upper_bound + 1):] | ||
28 | 28 | ||||
29 | def split_word(word): | 29 | def split_word(word): | ||
30 | return beginning(word), middle(word), end(word) | 30 | return beginning(word), middle(word), end(word) | ||
31 | 31 | ||||
32 | def split_sentence(sentence): | 32 | def split_sentence(sentence): | ||
33 | my_list = [] | 33 | my_list = [] | ||
34 | list_from_sentence = sentence.split() | 34 | list_from_sentence = sentence.split() | ||
35 | for word in list_from_sentence: | 35 | for word in list_from_sentence: | ||
36 | my_list.append(split_word(word)) | 36 | my_list.append(split_word(word)) | ||
37 | return my_list | 37 | return my_list | ||
t | t | 38 | |||
39 | print(split_sentence('Kазвам се Джон Сноу')) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | length = len(word) | 2 | length = len(word) | ||
3 | upper_bound = length // 3 | 3 | upper_bound = length // 3 | ||
4 | if length % 3 == 0 or length % 3 == 1: | 4 | if length % 3 == 0 or length % 3 == 1: | ||
5 | return word[:upper_bound] | 5 | return word[:upper_bound] | ||
6 | elif length % 3 == 2: | 6 | elif length % 3 == 2: | ||
7 | return word[:(upper_bound + 1)] | 7 | return word[:(upper_bound + 1)] | ||
8 | 8 | ||||
9 | def middle(word): | 9 | def middle(word): | ||
10 | length = len(word) | 10 | length = len(word) | ||
11 | upper_bound = length // 3 | 11 | upper_bound = length // 3 | ||
12 | if length % 3 == 0: | 12 | if length % 3 == 0: | ||
13 | return word[upper_bound:(upper_bound*2)] | 13 | return word[upper_bound:(upper_bound*2)] | ||
14 | elif length % 3 == 2: | 14 | elif length % 3 == 2: | ||
15 | return word[upper_bound+1:(2*upper_bound + 1)] | 15 | return word[upper_bound+1:(2*upper_bound + 1)] | ||
16 | elif length % 3 == 1: | 16 | elif length % 3 == 1: | ||
17 | return word[upper_bound:(2*upper_bound + 1)] | 17 | return word[upper_bound:(2*upper_bound + 1)] | ||
18 | 18 | ||||
19 | def end(word): | 19 | def end(word): | ||
20 | length = len(word) | 20 | length = len(word) | ||
21 | upper_bound = length // 3 | 21 | upper_bound = length // 3 | ||
22 | if length % 3 == 0: | 22 | if length % 3 == 0: | ||
23 | return word[(upper_bound*2):] | 23 | return word[(upper_bound*2):] | ||
24 | elif length % 3 == 2: | 24 | elif length % 3 == 2: | ||
25 | return word[(2*upper_bound + 1):] | 25 | return word[(2*upper_bound + 1):] | ||
26 | elif length % 3 == 1: | 26 | elif length % 3 == 1: | ||
27 | return word[(2 * upper_bound + 1):] | 27 | return word[(2 * upper_bound + 1):] | ||
28 | 28 | ||||
29 | def split_word(word): | 29 | def split_word(word): | ||
30 | return beginning(word), middle(word), end(word) | 30 | return beginning(word), middle(word), end(word) | ||
31 | 31 | ||||
32 | def split_sentence(sentence): | 32 | def split_sentence(sentence): | ||
33 | my_list = [] | 33 | my_list = [] | ||
34 | list_from_sentence = sentence.split() | 34 | list_from_sentence = sentence.split() | ||
35 | for word in list_from_sentence: | 35 | for word in list_from_sentence: | ||
36 | my_list.append(split_word(word)) | 36 | my_list.append(split_word(word)) | ||
37 | return my_list | 37 | return my_list | ||
t | 38 | t | |||
39 | print(split_sentence('Kазвам се Джон Сноу')) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def beginning(word): | f | 1 | def beginning(word): |
2 | length = len(word) | 2 | length = len(word) | ||
n | 3 | upperBound = length // 3 | n | 3 | upper_bound = length // 3 |
4 | if length % 3 == 0 or length % 3 == 1: | 4 | if length % 3 == 0 or length % 3 == 1: | ||
n | 5 | return word[0:upperBound] | n | 5 | return word[:upper_bound] |
6 | elif length % 3 == 2: | 6 | elif length % 3 == 2: | ||
n | 7 | return word[0:(upperBound + 1)] | n | 7 | return word[:(upper_bound + 1)] |
8 | 8 | ||||
9 | def middle(word): | 9 | def middle(word): | ||
10 | length = len(word) | 10 | length = len(word) | ||
n | 11 | upperBound = length // 3 | n | 11 | upper_bound = length // 3 |
12 | if length % 3 == 0: | 12 | if length % 3 == 0: | ||
n | 13 | return word[upperBound:(upperBound*2)] | n | 13 | return word[upper_bound:(upper_bound*2)] |
14 | elif length % 3 == 2: | 14 | elif length % 3 == 2: | ||
n | 15 | return word[upperBound+1:(2*upperBound + 1)] | n | 15 | return word[upper_bound+1:(2*upper_bound + 1)] |
16 | elif length % 3 == 1: | 16 | elif length % 3 == 1: | ||
n | 17 | return word[upperBound:(2*upperBound + 1)] | n | 17 | return word[upper_bound:(2*upper_bound + 1)] |
18 | 18 | ||||
19 | def end(word): | 19 | def end(word): | ||
20 | length = len(word) | 20 | length = len(word) | ||
n | 21 | upperBound = length // 3 | n | 21 | upper_bound = length // 3 |
22 | if length % 3 == 0: | 22 | if length % 3 == 0: | ||
n | 23 | return word[(upperBound*2):length] | n | 23 | return word[(upper_bound*2):] |
24 | elif length % 3 == 2: | 24 | elif length % 3 == 2: | ||
n | 25 | return word[(2*upperBound + 1):length] | n | 25 | return word[(2*upper_bound + 1):] |
26 | elif length % 3 == 1: | 26 | elif length % 3 == 1: | ||
n | 27 | return word[(2 * upperBound + 1):length] | n | 27 | return word[(2 * upper_bound + 1):] |
28 | 28 | ||||
n | 29 | def make_tuple(word): | n | 29 | def split_word(word): |
30 | return beginning(word), middle(word), end(word) | 30 | return beginning(word), middle(word), end(word) | ||
31 | 31 | ||||
32 | def split_sentence(sentence): | 32 | def split_sentence(sentence): | ||
33 | my_list = [] | 33 | my_list = [] | ||
34 | list_from_sentence = sentence.split() | 34 | list_from_sentence = sentence.split() | ||
n | 35 | for i in range(0, len(list_from_sentence)): | n | 35 | for word in list_from_sentence: |
36 | my_list.append(make_tuple(list_from_sentence[i])) | 36 | my_list.append(split_word(word)) | ||
37 | return my_list | 37 | return my_list | ||
t | t | 38 | |||
39 | print(split_sentence('Kазвам се Джон Сноу')) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
16.10.2023 19:29