f | def beginning(word): | f | def beginning(word): |
n | '''This function derives the beginning of a word from it, keeping in mind the remainder of the division of the word`s length by 3''' | n | '''Derive the beginning of a word, keeping in mind the remainder of the division of the word`s length by 3.''' |
| length = len(word) | | length = len(word) |
| if length % 3 == 0: | | if length % 3 == 0: |
n | word1 = slice(length // 3) | n | return word[0:length // 3] |
| elif length % 3 == 1: | | elif length % 3 == 1: |
n | word1 = slice(length // 3) | n | return word[0:length // 3] |
| else: | | else: |
n | word1 = slice(length // 3 + 1) | n | return word[0:length // 3 + 1] |
| return word[word1] | | |
| | | |
| def middle(word): | | def middle(word): |
n | '''This function derives the middle of a word from it, keeping in mind the remainder of the division of the word`s length by 3''' | n | '''Derive the middle of a word, keeping in mind the remainder of the division of the word`s length by 3.''' |
| length = len(word) | | length = len(word) |
| if length % 3 == 0: | | if length % 3 == 0: |
n | word2 = slice(length // 3, 2 * (length // 3)) | n | return word[length // 3:2 * (length // 3)] |
| elif length % 3 == 1: | | elif length % 3 == 1: |
n | word2 = slice(length // 3, 2 *(length // 3) + 1) | n | return word[length // 3:2 * (length // 3) + 1] |
| else: | | else: |
n | word2 = slice(length // 3 + 1, 2 * (length // 3) + 1) | n | return word[length // 3 + 1:2 * (length // 3) + 1] |
| return word[word2] | | |
| | | |
| def end(word): | | def end(word): |
n | '''This function derives the end of a word from it, keeping in mind the remainder of the division of the word`s length by 3''' | n | '''Derive the end of a word, keeping in mind the remainder of the division of the word`s length by 3.''' |
| length = len(word) | | length = len(word) |
| if length % 3 == 0: | | if length % 3 == 0: |
n | word3 = slice(2 * (length // 3), length) | n | return word[2 * (length // 3):length] |
| elif length % 3 == 1: | | elif length % 3 == 1: |
n | word3 = slice(2 *(length // 3) + 1, length) | n | return word[2 * (length // 3) + 1:length] |
| else: | | else: |
n | word3 = slice(2 *(length // 3) + 1, length) | n | return word[2 * (length // 3) + 1:length] |
| return word[word3] | | |
| | | |
| def split_sentence(sentence): | | def split_sentence(sentence): |
n | '''This function turns a string into a list of tuples (taking into account the rules that have been implemented in the first three functions)''' | n | '''Turn a string into a list of tuples, taking into account the rules that have been implemented in the first three functions.''' |
| words_list = sentence.split() | | words_list = sentence.split() |
| result = [] | | result = [] |
| for word in words_list: | | for word in words_list: |
t | b = beginning(word) # b = beginning of current word | t | result.append((beginning(word), middle(word), end(word))) |
| m = middle(word) # m = middle of current word | | |
| e = end(word) # e = end of current word | | |
| result.append((b, m, e)) | | |
| return result | | return result |