1def beginning(word):
2 word_length = len(word)
3 if word_length % 3 == 2:
4 return word[:word_length // 3 + 1]
5 else:
6 return word[:word_length // 3]
7
8def middle(word):
9 word_length = len(word)
10 if word_length % 3 == 0:
11 return word[word_length // 3 : (word_length // 3) * 2]
12 elif word_length % 3 == 1:
13 return word[word_length // 3 : (word_length // 3) * 2 + 1]
14 else:
15 return word[word_length // 3 + 1 : (word_length // 3) * 2 + 1]
16
17def end(word):
18 word_length = len(word)
19 if word_length % 3 == 0:
20 return word[(word_length // 3) * 2:]
21 else:
22 return word[(word_length // 3) * 2 + 1:]
23
24def split_sentence(sentence):
25 words = []
26 sentence_to_words = sentence.split()
27 for word in sentence_to_words:
28 temp_tuple = (beginning(word), middle(word), end(word))
29 words.append(temp_tuple)
30 return words
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
| 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 == 2: | 3 | if word_length % 3 == 2: | ||
| 4 | return word[:word_length // 3 + 1] | 4 | return word[:word_length // 3 + 1] | ||
| 5 | else: | 5 | else: | ||
| 6 | return word[:word_length // 3] | 6 | return word[:word_length // 3] | ||
| 7 | 7 | ||||
| 8 | def middle(word): | 8 | def middle(word): | ||
| 9 | word_length = len(word) | 9 | word_length = len(word) | ||
| 10 | if word_length % 3 == 0: | 10 | if word_length % 3 == 0: | ||
| 11 | return word[word_length // 3 : (word_length // 3) * 2] | 11 | return word[word_length // 3 : (word_length // 3) * 2] | ||
| 12 | elif word_length % 3 == 1: | 12 | elif word_length % 3 == 1: | ||
| 13 | return word[word_length // 3 : (word_length // 3) * 2 + 1] | 13 | return word[word_length // 3 : (word_length // 3) * 2 + 1] | ||
| 14 | else: | 14 | else: | ||
| 15 | return word[word_length // 3 + 1 : (word_length // 3) * 2 + 1] | 15 | return word[word_length // 3 + 1 : (word_length // 3) * 2 + 1] | ||
| 16 | 16 | ||||
| 17 | def end(word): | 17 | def end(word): | ||
| 18 | word_length = len(word) | 18 | word_length = len(word) | ||
| 19 | if word_length % 3 == 0: | 19 | if word_length % 3 == 0: | ||
| 20 | return word[(word_length // 3) * 2:] | 20 | return word[(word_length // 3) * 2:] | ||
| 21 | else: | 21 | else: | ||
| 22 | return word[(word_length // 3) * 2 + 1:] | 22 | return word[(word_length // 3) * 2 + 1:] | ||
| 23 | 23 | ||||
| n | 24 | def split_sentence(str): | n | 24 | def split_sentence(sentence): |
| 25 | words = [] | 25 | words = [] | ||
| t | 26 | sentence_to_words = str.split() | t | 26 | sentence_to_words = sentence.split() |
| 27 | for i in sentence_to_words: | 27 | for word in sentence_to_words: | ||
| 28 | temp_tuple = (beginning(i), middle(i), end(i)) | 28 | temp_tuple = (beginning(word), middle(word), end(word)) | ||
| 29 | words.append(temp_tuple) | 29 | words.append(temp_tuple) | ||
| 30 | return words | 30 | return words |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||