1def beginning(word: str):
2 word_len = len(word)
3 if word_len % 3 == 2:
4 return word[: word_len // 3 + 1]
5 return word[: word_len // 3]
6
7
8def middle(word: str):
9 word_len = len(word)
10 if word_len % 3 == 0:
11 return word[word_len // 3: word_len // 3 * 2]
12 elif word_len % 3 == 1:
13 return word[word_len // 3: word_len // 3 * 2 + 1]
14 else:
15 return word[(word_len // 3) + 1: word_len // 3 * 2 + 1]
16
17
18def end(word: str):
19 word_len = len(word)
20 if word_len % 3 == 0:
21 return word[(word_len // 3) * 2:]
22 return word[word_len // 3 * 2 + 1:]
23
24
25def split_sentence(sentence: str):
26 words = []
27 for word in sentence.split():
28 words.append((beginning(word), middle(word), end(word)))
29 return words
30
31
32if __name__ == "__main__":
33 print(split_sentence('Kазвам се Джон Сноу'))
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
f | 1 | def beginning(word: str): | f | 1 | def beginning(word: str): |
2 | word_len = len(word) | 2 | word_len = len(word) | ||
3 | if word_len % 3 == 2: | 3 | if word_len % 3 == 2: | ||
n | 4 | return word[:word_len // 3 + 1] | n | 4 | return word[: word_len // 3 + 1] |
5 | return word[: word_len // 3] | 5 | return word[: word_len // 3] | ||
6 | 6 | ||||
7 | 7 | ||||
8 | def middle(word: str): | 8 | def middle(word: str): | ||
9 | word_len = len(word) | 9 | word_len = len(word) | ||
10 | if word_len % 3 == 0: | 10 | if word_len % 3 == 0: | ||
11 | return word[word_len // 3: word_len // 3 * 2] | 11 | return word[word_len // 3: word_len // 3 * 2] | ||
12 | elif word_len % 3 == 1: | 12 | elif word_len % 3 == 1: | ||
13 | return word[word_len // 3: word_len // 3 * 2 + 1] | 13 | return word[word_len // 3: word_len // 3 * 2 + 1] | ||
14 | else: | 14 | else: | ||
15 | return word[(word_len // 3) + 1: word_len // 3 * 2 + 1] | 15 | return word[(word_len // 3) + 1: word_len // 3 * 2 + 1] | ||
16 | 16 | ||||
17 | 17 | ||||
18 | def end(word: str): | 18 | def end(word: str): | ||
19 | word_len = len(word) | 19 | word_len = len(word) | ||
20 | if word_len % 3 == 0: | 20 | if word_len % 3 == 0: | ||
21 | return word[(word_len // 3) * 2:] | 21 | return word[(word_len // 3) * 2:] | ||
22 | return word[word_len // 3 * 2 + 1:] | 22 | return word[word_len // 3 * 2 + 1:] | ||
23 | 23 | ||||
24 | 24 | ||||
25 | def split_sentence(sentence: str): | 25 | def split_sentence(sentence: str): | ||
26 | words = [] | 26 | words = [] | ||
t | 27 | for word in sentence.split(' '): | t | 27 | for word in sentence.split(): |
28 | new_word = (beginning(word), middle(word), end(word)) | 28 | words.append((beginning(word), middle(word), end(word))) | ||
29 | words.append(new_word) | ||||
30 | return words | 29 | return words | ||
31 | 30 | ||||
32 | 31 | ||||
33 | if __name__ == "__main__": | 32 | if __name__ == "__main__": | ||
34 | print(split_sentence('Kазвам се Джон Сноу')) | 33 | print(split_sentence('Kазвам се Джон Сноу')) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
t | 1 | import math | t | ||
2 | |||||
3 | |||||
4 | def beginning(word: str): | 1 | def beginning(word: str): | ||
5 | word_len = len(word) | 2 | word_len = len(word) | ||
6 | if word_len % 3 == 2: | 3 | if word_len % 3 == 2: | ||
7 | return word[:word_len // 3 + 1] | 4 | return word[:word_len // 3 + 1] | ||
8 | return word[: word_len // 3] | 5 | return word[: word_len // 3] | ||
9 | 6 | ||||
10 | 7 | ||||
11 | def middle(word: str): | 8 | def middle(word: str): | ||
12 | word_len = len(word) | 9 | word_len = len(word) | ||
13 | if word_len % 3 == 0: | 10 | if word_len % 3 == 0: | ||
14 | return word[word_len // 3: word_len // 3 * 2] | 11 | return word[word_len // 3: word_len // 3 * 2] | ||
15 | elif word_len % 3 == 1: | 12 | elif word_len % 3 == 1: | ||
16 | return word[word_len // 3: word_len // 3 * 2 + 1] | 13 | return word[word_len // 3: word_len // 3 * 2 + 1] | ||
17 | else: | 14 | else: | ||
18 | return word[(word_len // 3) + 1: word_len // 3 * 2 + 1] | 15 | return word[(word_len // 3) + 1: word_len // 3 * 2 + 1] | ||
19 | 16 | ||||
20 | 17 | ||||
21 | def end(word: str): | 18 | def end(word: str): | ||
22 | word_len = len(word) | 19 | word_len = len(word) | ||
23 | if word_len % 3 == 0: | 20 | if word_len % 3 == 0: | ||
24 | return word[(word_len // 3) * 2:] | 21 | return word[(word_len // 3) * 2:] | ||
25 | return word[word_len // 3 * 2 + 1:] | 22 | return word[word_len // 3 * 2 + 1:] | ||
26 | 23 | ||||
27 | 24 | ||||
28 | def split_sentence(sentence: str): | 25 | def split_sentence(sentence: str): | ||
29 | words = [] | 26 | words = [] | ||
30 | for word in sentence.split(' '): | 27 | for word in sentence.split(' '): | ||
31 | new_word = (beginning(word), middle(word), end(word)) | 28 | new_word = (beginning(word), middle(word), end(word)) | ||
32 | words.append(new_word) | 29 | words.append(new_word) | ||
33 | return words | 30 | return words | ||
34 | 31 | ||||
35 | 32 | ||||
36 | if __name__ == "__main__": | 33 | if __name__ == "__main__": | ||
37 | print(split_sentence('Kазвам се Джон Сноу')) | 34 | print(split_sentence('Kазвам се Джон Сноу')) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|