1def beginning(word):
2 remainder = len(word) % 3
3 part = len(word) // 3
4 if remainder == 0:
5 return word[:part]
6 elif remainder == 2:
7 return word[:part + 1]
8 return word[:part]
9
10def middle(word):
11 remainder = len(word) % 3
12 part = len(word) // 3
13 if remainder == 0:
14 return word[part:2 * part]
15 elif remainder == 2:
16 return word[part + 1:2 * part + 1]
17 return word[part:2 * part + 1]
18
19def end(word):
20 remainder = len(word) % 3
21 part = len(word) // 3
22 if remainder == 0:
23 return word[2 * part:]
24 elif remainder == 2:
25 return word[2 * part + 1:]
26 return word[2 * part + 1:]
27
28def separate_word(word):
29 return (beginning(word), middle(word), end(word))
30
31def split_sentence(sentence):
32 return list(map(separate_word, sentence.split()))
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
| f | 1 | def beginning(word): | f | 1 | def beginning(word): |
| n | 2 | remainder = len(word)%3 | n | 2 | remainder = len(word) % 3 |
| 3 | part = len(word)//3 | 3 | part = len(word) // 3 | ||
| 4 | if remainder == 0: | 4 | if remainder == 0: | ||
| 5 | return word[:part] | 5 | return word[:part] | ||
| 6 | elif remainder == 2: | 6 | elif remainder == 2: | ||
| n | 7 | return word[:part+1] | n | 7 | return word[:part + 1] |
| 8 | return word[:part] | 8 | return word[:part] | ||
| 9 | 9 | ||||
| 10 | def middle(word): | 10 | def middle(word): | ||
| n | 11 | remainder = len(word)%3 | n | 11 | remainder = len(word) % 3 |
| 12 | part = len(word)//3 | 12 | part = len(word) // 3 | ||
| 13 | if remainder == 0: | 13 | if remainder == 0: | ||
| n | 14 | return word[part:2*part] | n | 14 | return word[part:2 * part] |
| 15 | elif remainder == 2: | 15 | elif remainder == 2: | ||
| n | 16 | return word[part+1:2*part+1] | n | 16 | return word[part + 1:2 * part + 1] |
| 17 | return word[part:2*part+1] | 17 | return word[part:2 * part + 1] | ||
| 18 | 18 | ||||
| 19 | def end(word): | 19 | def end(word): | ||
| n | 20 | remainder = len(word)%3 | n | 20 | remainder = len(word) % 3 |
| 21 | part = len(word)//3 | 21 | part = len(word) // 3 | ||
| 22 | if remainder == 0: | 22 | if remainder == 0: | ||
| n | 23 | return word[2*part:] | n | 23 | return word[2 * part:] |
| 24 | elif remainder == 2: | 24 | elif remainder == 2: | ||
| n | 25 | return word[2*part+1:] | n | 25 | return word[2 * part + 1:] |
| 26 | return word[2*part+1:] | 26 | return word[2 * part + 1:] | ||
| 27 | 27 | ||||
| n | 28 | def make_tuple (word): | n | 28 | def separate_word(word): |
| 29 | return (beginning(word), middle(word), end(word)) | 29 | return (beginning(word), middle(word), end(word)) | ||
| 30 | 30 | ||||
| 31 | def split_sentence(sentence): | 31 | def split_sentence(sentence): | ||
| n | 32 | word = '' | n | 32 | return list(map(separate_word, sentence.split())) |
| 33 | words = [] | ||||
| 34 | for letter in sentence: | ||||
| 35 | if letter != ' ': | ||||
| 36 | word += letter | ||||
| 37 | else: | ||||
| 38 | words.append(word) | ||||
| 39 | word = '' | ||||
| 40 | words.append(word) | ||||
| 41 | return list(map(make_tuple, words)) | ||||
| 42 | 33 | ||||
| t | t | 34 |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| f | 1 | def beginning(word): | f | 1 | def beginning(word): |
| 2 | remainder = len(word)%3 | 2 | remainder = len(word)%3 | ||
| 3 | part = len(word)//3 | 3 | part = len(word)//3 | ||
| 4 | if remainder == 0: | 4 | if remainder == 0: | ||
| 5 | return word[:part] | 5 | return word[:part] | ||
| 6 | elif remainder == 2: | 6 | elif remainder == 2: | ||
| 7 | return word[:part+1] | 7 | return word[:part+1] | ||
| 8 | return word[:part] | 8 | return word[:part] | ||
| 9 | 9 | ||||
| 10 | def middle(word): | 10 | def middle(word): | ||
| 11 | remainder = len(word)%3 | 11 | remainder = len(word)%3 | ||
| 12 | part = len(word)//3 | 12 | part = len(word)//3 | ||
| 13 | if remainder == 0: | 13 | if remainder == 0: | ||
| 14 | return word[part:2*part] | 14 | return word[part:2*part] | ||
| 15 | elif remainder == 2: | 15 | elif remainder == 2: | ||
| 16 | return word[part+1:2*part+1] | 16 | return word[part+1:2*part+1] | ||
| 17 | return word[part:2*part+1] | 17 | return word[part:2*part+1] | ||
| 18 | 18 | ||||
| 19 | def end(word): | 19 | def end(word): | ||
| 20 | remainder = len(word)%3 | 20 | remainder = len(word)%3 | ||
| 21 | part = len(word)//3 | 21 | part = len(word)//3 | ||
| 22 | if remainder == 0: | 22 | if remainder == 0: | ||
| 23 | return word[2*part:] | 23 | return word[2*part:] | ||
| 24 | elif remainder == 2: | 24 | elif remainder == 2: | ||
| 25 | return word[2*part+1:] | 25 | return word[2*part+1:] | ||
| 26 | return word[2*part+1:] | 26 | return word[2*part+1:] | ||
| 27 | 27 | ||||
| 28 | def make_tuple (word): | 28 | def make_tuple (word): | ||
| 29 | return (beginning(word), middle(word), end(word)) | 29 | return (beginning(word), middle(word), end(word)) | ||
| 30 | 30 | ||||
| 31 | def split_sentence(sentence): | 31 | def split_sentence(sentence): | ||
| 32 | word = '' | 32 | word = '' | ||
| 33 | words = [] | 33 | words = [] | ||
| 34 | for letter in sentence: | 34 | for letter in sentence: | ||
| 35 | if letter != ' ': | 35 | if letter != ' ': | ||
| 36 | word += letter | 36 | word += letter | ||
| 37 | else: | 37 | else: | ||
| 38 | words.append(word) | 38 | words.append(word) | ||
| 39 | word = '' | 39 | word = '' | ||
| n | n | 40 | words.append(word) | ||
| 40 | return list(map(make_tuple, words)) | 41 | return list(map(make_tuple, words)) | ||
| t | 41 | t | 42 | ||
| 42 | word = 'qwew' | ||||
| 43 | part = len(word)//3 | ||||
| 44 | print(make_tuple(word)) | ||||
| 45 | print (len(word)) | ||||
| 46 | print (part) | ||||
| 47 | sentence = 'Kазвам се Джон Сноу' | ||||
| 48 | print (split_sentence(sentence)) |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| t | 1 | def beginning(word): | t | 1 | def beginning(word): |
| 2 | remainder = len(word)%3 | 2 | remainder = len(word)%3 | ||
| 3 | part = len(word)//3 | 3 | part = len(word)//3 | ||
| 4 | if remainder == 0: | 4 | if remainder == 0: | ||
| 5 | return word[:part] | 5 | return word[:part] | ||
| 6 | elif remainder == 2: | 6 | elif remainder == 2: | ||
| 7 | return word[:part+1] | 7 | return word[:part+1] | ||
| 8 | return word[:part] | 8 | return word[:part] | ||
| 9 | 9 | ||||
| 10 | def middle(word): | 10 | def middle(word): | ||
| 11 | remainder = len(word)%3 | 11 | remainder = len(word)%3 | ||
| 12 | part = len(word)//3 | 12 | part = len(word)//3 | ||
| 13 | if remainder == 0: | 13 | if remainder == 0: | ||
| 14 | return word[part:2*part] | 14 | return word[part:2*part] | ||
| 15 | elif remainder == 2: | 15 | elif remainder == 2: | ||
| 16 | return word[part+1:2*part+1] | 16 | return word[part+1:2*part+1] | ||
| 17 | return word[part:2*part+1] | 17 | return word[part:2*part+1] | ||
| 18 | 18 | ||||
| 19 | def end(word): | 19 | def end(word): | ||
| 20 | remainder = len(word)%3 | 20 | remainder = len(word)%3 | ||
| 21 | part = len(word)//3 | 21 | part = len(word)//3 | ||
| 22 | if remainder == 0: | 22 | if remainder == 0: | ||
| 23 | return word[2*part:] | 23 | return word[2*part:] | ||
| 24 | elif remainder == 2: | 24 | elif remainder == 2: | ||
| 25 | return word[2*part+1:] | 25 | return word[2*part+1:] | ||
| 26 | return word[2*part+1:] | 26 | return word[2*part+1:] | ||
| 27 | 27 | ||||
| 28 | def make_tuple (word): | 28 | def make_tuple (word): | ||
| 29 | return (beginning(word), middle(word), end(word)) | 29 | return (beginning(word), middle(word), end(word)) | ||
| 30 | 30 | ||||
| 31 | def split_sentence(sentence): | 31 | def split_sentence(sentence): | ||
| 32 | word = '' | 32 | word = '' | ||
| 33 | words = [] | 33 | words = [] | ||
| 34 | for letter in sentence: | 34 | for letter in sentence: | ||
| 35 | if letter != ' ': | 35 | if letter != ' ': | ||
| 36 | word += letter | 36 | word += letter | ||
| 37 | else: | 37 | else: | ||
| 38 | words.append(word) | 38 | words.append(word) | ||
| 39 | word = '' | 39 | word = '' | ||
| 40 | return list(map(make_tuple, words)) | 40 | return list(map(make_tuple, words)) | ||
| 41 | 41 | ||||
| 42 | word = 'qwew' | 42 | word = 'qwew' | ||
| 43 | part = len(word)//3 | 43 | part = len(word)//3 | ||
| 44 | print(make_tuple(word)) | 44 | print(make_tuple(word)) | ||
| 45 | print (len(word)) | 45 | print (len(word)) | ||
| 46 | print (part) | 46 | print (part) | ||
| 47 | sentence = 'Kазвам се Джон Сноу' | 47 | sentence = 'Kазвам се Джон Сноу' | ||
| 48 | print (split_sentence(sentence)) | 48 | print (split_sentence(sentence)) |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||