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