1def beginning(word):
2 word_length = len(word)
3 if word_length%3 == 0 or word_length%3 == 1:
4 offset = word_length//3
5 return word[0:offset]
6 elif word_length%3 == 2:
7 offset = word_length//3+1
8 return word[0:offset]
9
10def middle(word):
11 word_length = len(word)
12 if word_length%3 == 0:
13 offset = word_length//3
14 return word[offset:offset+offset]
15 elif word_length%3 == 2:
16 offset = word_length//3
17 return word[offset+1:offset+offset+1]
18 else:
19 offset = word_length//3
20 return word[offset:offset+offset+1]
21
22def end(word):
23 word_length = len(word)
24 if word_length%3 == 0:
25 offset = word_length//3
26 return ''.join(reversed(word[word_length:offset+offset-1:-1]))
27 elif word_length%3== 2 or word_length%3==1:
28 offset=word_length//3
29 return ''.join(reversed(word[word_length:offset+offset:-1]))
30
31def split_sentence(sentence):
32 split_in_words = sentence.split()
33 list_of_tuples = []
34 for word in split_in_words:
35 list_of_tuples.append((beginning(word),middle(word),end(word)))
36 return list_of_tuples
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
| f | 1 | def beginning(word): | f | 1 | def beginning(word): |
| n | 2 | word_length=len(word) | n | 2 | word_length = len(word) |
| 3 | if word_length%3== 0: | 3 | if word_length%3 == 0 or word_length%3 == 1: | ||
| 4 | offset=word_length//3 | 4 | offset = word_length//3 | ||
| 5 | return word[0:offset] | 5 | return word[0:offset] | ||
| n | 6 | elif word_length%3== 2: | n | 6 | elif word_length%3 == 2: |
| 7 | offset=word_length//3+1 | 7 | offset = word_length//3+1 | ||
| 8 | return word[0:offset] | 8 | return word[0:offset] | ||
| n | 9 | else: | n | 9 | |
| 10 | offset=word_length//3 | ||||
| 11 | return word[0:offset] | ||||
| 12 | def middle(word): | 10 | def middle(word): | ||
| n | 13 | word_length=len(word) | n | 11 | word_length = len(word) |
| 14 | if word_length%3== 0: | 12 | if word_length%3 == 0: | ||
| 15 | offset=word_length//3 | 13 | offset = word_length//3 | ||
| 16 | return word[offset:offset+offset] | 14 | return word[offset:offset+offset] | ||
| n | 17 | elif word_length%3== 2: | n | 15 | elif word_length%3 == 2: |
| 18 | offset=word_length//3 | 16 | offset = word_length//3 | ||
| 19 | return word[offset+1:offset+offset+1] | 17 | return word[offset+1:offset+offset+1] | ||
| 20 | else: | 18 | else: | ||
| n | 21 | offset=word_length//3 | n | 19 | offset = word_length//3 |
| 22 | return word[offset:offset+offset+1] | 20 | return word[offset:offset+offset+1] | ||
| n | n | 21 | |||
| 23 | def end(word): | 22 | def end(word): | ||
| n | 24 | word_length=len(word) | n | 23 | word_length = len(word) |
| 25 | if word_length%3== 0: | 24 | if word_length%3 == 0: | ||
| 26 | offset=word_length//3 | 25 | offset = word_length//3 | ||
| 27 | return ''.join(reversed(word[word_length:offset+offset-1:-1])) | 26 | return ''.join(reversed(word[word_length:offset+offset-1:-1])) | ||
| n | 28 | elif word_length%3== 2: | n | 27 | elif word_length%3== 2 or word_length%3==1: |
| 29 | offset=word_length//3 | ||||
| 30 | return ''.join(reversed(word[word_length:offset+offset:-1])) | ||||
| 31 | else: | ||||
| 32 | offset=word_length//3 | 28 | offset=word_length//3 | ||
| 33 | return ''.join(reversed(word[word_length:offset+offset:-1])) | 29 | return ''.join(reversed(word[word_length:offset+offset:-1])) | ||
| 34 | 30 | ||||
| 35 | def split_sentence(sentence): | 31 | def split_sentence(sentence): | ||
| t | 36 | split_in_words=sentence.split() | t | 32 | split_in_words = sentence.split() |
| 37 | list_of_tuples=[] | 33 | list_of_tuples = [] | ||
| 38 | for word in split_in_words: | 34 | for word in split_in_words: | ||
| 39 | list_of_tuples.append((beginning(word),middle(word),end(word))) | 35 | list_of_tuples.append((beginning(word),middle(word),end(word))) | ||
| 40 | return list_of_tuples | 36 | return list_of_tuples |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| f | 1 | def beginning(word): | f | 1 | def beginning(word): |
| 2 | word_length=len(word) | 2 | word_length=len(word) | ||
| 3 | if word_length%3== 0: | 3 | if word_length%3== 0: | ||
| 4 | offset=word_length//3 | 4 | offset=word_length//3 | ||
| 5 | return word[0:offset] | 5 | return word[0:offset] | ||
| 6 | elif word_length%3== 2: | 6 | elif word_length%3== 2: | ||
| 7 | offset=word_length//3+1 | 7 | offset=word_length//3+1 | ||
| 8 | return word[0:offset] | 8 | return word[0:offset] | ||
| 9 | else: | 9 | else: | ||
| 10 | offset=word_length//3 | 10 | offset=word_length//3 | ||
| 11 | return word[0:offset] | 11 | return word[0:offset] | ||
| 12 | def middle(word): | 12 | def middle(word): | ||
| 13 | word_length=len(word) | 13 | word_length=len(word) | ||
| 14 | if word_length%3== 0: | 14 | if word_length%3== 0: | ||
| 15 | offset=word_length//3 | 15 | offset=word_length//3 | ||
| 16 | return word[offset:offset+offset] | 16 | return word[offset:offset+offset] | ||
| 17 | elif word_length%3== 2: | 17 | elif word_length%3== 2: | ||
| 18 | offset=word_length//3 | 18 | offset=word_length//3 | ||
| 19 | return word[offset+1:offset+offset+1] | 19 | return word[offset+1:offset+offset+1] | ||
| 20 | else: | 20 | else: | ||
| 21 | offset=word_length//3 | 21 | offset=word_length//3 | ||
| 22 | return word[offset:offset+offset+1] | 22 | return word[offset:offset+offset+1] | ||
| 23 | def end(word): | 23 | def end(word): | ||
| 24 | word_length=len(word) | 24 | word_length=len(word) | ||
| 25 | if word_length%3== 0: | 25 | if word_length%3== 0: | ||
| 26 | offset=word_length//3 | 26 | offset=word_length//3 | ||
| 27 | return ''.join(reversed(word[word_length:offset+offset-1:-1])) | 27 | return ''.join(reversed(word[word_length:offset+offset-1:-1])) | ||
| 28 | elif word_length%3== 2: | 28 | elif word_length%3== 2: | ||
| 29 | offset=word_length//3 | 29 | offset=word_length//3 | ||
| 30 | return ''.join(reversed(word[word_length:offset+offset:-1])) | 30 | return ''.join(reversed(word[word_length:offset+offset:-1])) | ||
| 31 | else: | 31 | else: | ||
| 32 | offset=word_length//3 | 32 | offset=word_length//3 | ||
| 33 | return ''.join(reversed(word[word_length:offset+offset:-1])) | 33 | return ''.join(reversed(word[word_length:offset+offset:-1])) | ||
| 34 | 34 | ||||
| 35 | def split_sentence(sentence): | 35 | def split_sentence(sentence): | ||
| 36 | split_in_words=sentence.split() | 36 | split_in_words=sentence.split() | ||
| 37 | list_of_tuples=[] | 37 | list_of_tuples=[] | ||
| 38 | for word in split_in_words: | 38 | for word in split_in_words: | ||
| 39 | list_of_tuples.append((beginning(word),middle(word),end(word))) | 39 | list_of_tuples.append((beginning(word),middle(word),end(word))) | ||
| 40 | return list_of_tuples | 40 | return list_of_tuples | ||
| t | 41 | print(split_sentence('обичам те')) | t |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
| t | 1 | def beginning(word): | t | 1 | def beginning(word): |
| 2 | word_length=len(word) | 2 | word_length=len(word) | ||
| 3 | if word_length%3== 0: | 3 | if word_length%3== 0: | ||
| 4 | offset=word_length//3 | 4 | offset=word_length//3 | ||
| 5 | return word[0:offset] | 5 | return word[0:offset] | ||
| 6 | elif word_length%3== 2: | 6 | elif word_length%3== 2: | ||
| 7 | offset=word_length//3+1 | 7 | offset=word_length//3+1 | ||
| 8 | return word[0:offset] | 8 | return word[0:offset] | ||
| 9 | else: | 9 | else: | ||
| 10 | offset=word_length//3 | 10 | offset=word_length//3 | ||
| 11 | return word[0:offset] | 11 | return word[0:offset] | ||
| 12 | def middle(word): | 12 | def middle(word): | ||
| 13 | word_length=len(word) | 13 | word_length=len(word) | ||
| 14 | if word_length%3== 0: | 14 | if word_length%3== 0: | ||
| 15 | offset=word_length//3 | 15 | offset=word_length//3 | ||
| 16 | return word[offset:offset+offset] | 16 | return word[offset:offset+offset] | ||
| 17 | elif word_length%3== 2: | 17 | elif word_length%3== 2: | ||
| 18 | offset=word_length//3 | 18 | offset=word_length//3 | ||
| 19 | return word[offset+1:offset+offset+1] | 19 | return word[offset+1:offset+offset+1] | ||
| 20 | else: | 20 | else: | ||
| 21 | offset=word_length//3 | 21 | offset=word_length//3 | ||
| 22 | return word[offset:offset+offset+1] | 22 | return word[offset:offset+offset+1] | ||
| 23 | def end(word): | 23 | def end(word): | ||
| 24 | word_length=len(word) | 24 | word_length=len(word) | ||
| 25 | if word_length%3== 0: | 25 | if word_length%3== 0: | ||
| 26 | offset=word_length//3 | 26 | offset=word_length//3 | ||
| 27 | return ''.join(reversed(word[word_length:offset+offset-1:-1])) | 27 | return ''.join(reversed(word[word_length:offset+offset-1:-1])) | ||
| 28 | elif word_length%3== 2: | 28 | elif word_length%3== 2: | ||
| 29 | offset=word_length//3 | 29 | offset=word_length//3 | ||
| 30 | return ''.join(reversed(word[word_length:offset+offset:-1])) | 30 | return ''.join(reversed(word[word_length:offset+offset:-1])) | ||
| 31 | else: | 31 | else: | ||
| 32 | offset=word_length//3 | 32 | offset=word_length//3 | ||
| 33 | return ''.join(reversed(word[word_length:offset+offset:-1])) | 33 | return ''.join(reversed(word[word_length:offset+offset:-1])) | ||
| 34 | 34 | ||||
| 35 | def split_sentence(sentence): | 35 | def split_sentence(sentence): | ||
| 36 | split_in_words=sentence.split() | 36 | split_in_words=sentence.split() | ||
| 37 | list_of_tuples=[] | 37 | list_of_tuples=[] | ||
| 38 | for word in split_in_words: | 38 | for word in split_in_words: | ||
| 39 | list_of_tuples.append((beginning(word),middle(word),end(word))) | 39 | list_of_tuples.append((beginning(word),middle(word),end(word))) | ||
| 40 | return list_of_tuples | 40 | return list_of_tuples | ||
| 41 | print(split_sentence('обичам те')) | 41 | print(split_sentence('обичам те')) |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||