f | def beginning(word): | f | def beginning(word): |
| size = len(word) | | size = len(word) |
n | remainder = int(size % 3) | n | remainder = size % 3 |
| | | |
| if size == 0: | | if size == 0: |
| return '' | | return '' |
| elif remainder == 2: | | elif remainder == 2: |
| index = int(size / 3) + 1 | | index = int(size / 3) + 1 |
| else: | | else: |
| index = int(size / 3) | | index = int(size / 3) |
| | | |
| return word[:index] | | return word[:index] |
| | | |
| def middle(word): | | def middle(word): |
| size = len(word) | | size = len(word) |
n | remainder = int(size % 3) | n | remainder = size % 3 |
| | | |
| if size == 1: | | if size == 1: |
| return word[0] | | return word[0] |
| elif size == 2: | | elif size == 2: |
| return '' | | return '' |
n | elif remainder == 1: | n | elif remainder in (0 , 1): |
| index = int(size / 3) | | index = int(size / 3) |
n | elif remainder == 0: | n | return word[index : size - index] |
| index = int(size / 3) | | |
| else: | | else: |
| index = int(size / 3) | | index = int(size / 3) |
| return word[index + 1 : size - index - 1] | | return word[index + 1 : size - index - 1] |
n | | n | |
| return word[index : size - index] | | |
| | | |
| def end(word): | | def end(word): |
| size = len(word) | | size = len(word) |
n | remainder = int(size % 3) | n | remainder = size % 3 |
| | | |
| if size <= 1: | | if size <= 1: |
| return '' | | return '' |
| elif remainder == 2: | | elif remainder == 2: |
| index = int(size / 3) + 1 | | index = int(size / 3) + 1 |
| else: | | else: |
| index = int(size / 3) | | index = int(size / 3) |
| | | |
| return word[size - index :] | | return word[size - index :] |
| | | |
| def split_sentence(sentence): | | def split_sentence(sentence): |
| words_list = sentence.split() | | words_list = sentence.split() |
| result_list=[] | | result_list=[] |
t | | t | |
| for i in words_list: | | for i in words_list: |
| result_list.append((beginning(i), middle(i), end(i))) | | result_list.append((beginning(i), middle(i), end(i))) |
| | | |
| return result_list | | return result_list |
| | | |
| # some test cases I checked: | | # some test cases I checked: |
| | | |
| # print(beginning("nelina"), middle("nelina"), end("nelina")) | | # print(beginning("nelina"), middle("nelina"), end("nelina")) |
| # print( beginning("Пица"), middle("Пица"), end("пица")) | | # print( beginning("Пица"), middle("Пица"), end("пица")) |
| # print(beginning("барабани"), middle("барабани"), end("барабани")) | | # print(beginning("барабани"), middle("барабани"), end("барабани")) |
| # print(beginning("Враца"), middle("Враца"),end("Враца")) | | # print(beginning("Враца"), middle("Враца"),end("Враца")) |
| # print(beginning("123456654321"), middle("1234567654321"), end("1234567654321")) | | # print(beginning("123456654321"), middle("1234567654321"), end("1234567654321")) |
| # print(beginning("домашно"), middle("домашно"), end("домашно")) | | # print(beginning("домашно"), middle("домашно"), end("домашно")) |
| # print(beginning("aheloy"), middle("aheloy"), end("aheloy")) | | # print(beginning("aheloy"), middle("aheloy"), end("aheloy")) |
| # print(beginning("шах"), middle("шах"), end("шах")) | | # print(beginning("шах"), middle("шах"), end("шах")) |
| # print(beginning("пайтън"), middle("пайтън"), end("пайтън")) | | # print(beginning("пайтън"), middle("пайтън"), end("пайтън")) |
| # print(beginning("pa"), middle("pa"), end("pa")) | | # print(beginning("pa"), middle("pa"), end("pa")) |
| # print(beginning("p"), middle("p"), end("p")) | | # print(beginning("p"), middle("p"), end("p")) |
| # print(beginning(""), middle(""), end("")) | | # print(beginning(""), middle(""), end("")) |
| # print(beginning("pa/ra"), middle("pa/ra"), end("pa/ra")) | | # print(beginning("pa/ra"), middle("pa/ra"), end("pa/ra")) |
| | | |
| # print(split_sentence('Kазвам се Джон Сноу')) | | # print(split_sentence('Kазвам се Джон Сноу')) |
| # print(split_sentence('аз купих домати и краставици от магазина')) | | # print(split_sentence('аз купих домати и краставици от магазина')) |
| # print(split_sentence('О')) | | # print(split_sentence('О')) |
| # print(split_sentence('Ок')) | | # print(split_sentence('Ок')) |