n | def quot_rem(num, div): | n | def split_in(word, parts=3): |
| return num // div, num % div | | word_len = len(word) |
| | | return word_len // parts, word_len % parts |
| | | |
| | | |
| def beginning(word): | | def beginning(word): |
n | sub_len, rem = quot_rem(len(word), 3) | n | split, rem = split_in(word) |
| return word[:sub_len] if rem != 2 else word[:sub_len + 1] | | if rem == 2: |
| | | return word[:split + 1] |
| | | return word[:split] |
| | | |
| | | |
| def middle(word): | | def middle(word): |
n | sub_len, rem = quot_rem(len(word), 3) | n | split, rem = split_in(word) |
| if rem == 0: | | if rem == 0: |
n | return word[sub_len: 2 * sub_len] | n | return word[split: 2 * split] |
| elif rem == 1: | | elif rem == 1: |
n | return word[sub_len: 2 * sub_len + 1] | n | return word[split: 2 * split + 1] |
| else: | | else: |
n | return word[sub_len + 1: 2 * sub_len + 1] | n | return word[split + 1: 2 * split + 1] |
| | | |
| | | |
| def end(word): | | def end(word): |
t | sub_len, rem = quot_rem(len(word), 3) | t | split, rem = split_in(word) |
| return word[-sub_len:] if rem != 2 else word[-sub_len - 1:] | | if rem == 2: |
| | | return word[-split - 1:] |
| | | return word[-split:] if split > 0 else '' |
| | | |
| | | |
| def split_word(word): | | def split_word(word): |
| return beginning(word), middle(word), end(word) | | return beginning(word), middle(word), end(word) |
| | | |
| | | |
| def split_sentence(sentence): | | def split_sentence(sentence): |
| return [split_word(w) for w in sentence.split()] | | return [split_word(w) for w in sentence.split()] |