1def beginning(str):
2 if(len(str)%3 in [0, 1]):
3 position = slice(0, len(str)//3)
4 return str[position]
5 elif(len(str)%3 == 2):
6 position = slice(0, len(str)//3 + 1)
7 return str[position]
8
9def middle(str):
10 if(len(str)%3 == 0):
11 start_index = (int)(len(str)/3)
12 position = slice(start_index, start_index*2)
13 return str[position]
14 elif(len(str)%3 == 1):
15 start_index = (int)(len(str)/3)
16 position = slice(start_index, start_index*2 + 1)
17 return str[position]
18 elif(len(str)%3 == 2):
19 start_index = (int)(len(str)/3) + 1
20 position = slice(start_index, start_index*2 - 1)
21 return str[position]
22
23def end(str):
24 if(len(str)%3 == 0):
25 start_index = (int)(len(str)/3)*2
26 position = slice(start_index, len(str))
27 return str[position]
28 elif(len(str)%3 == 1):
29 start_index = (int)(len(str)/3)*2 +1
30 position = slice(start_index, len(str))
31 return str[position]
32 elif(len(str)%3 == 2):
33 start_index = (int)(len(str)/3)*2 + 1
34 position = slice(start_index, len(str))
35 return str[position]
36
37def split_sentence(sentence):
38 result = []
39 for word in sentence.split(' '):
40 curr_word_tuple = (
41 beginning(word),
42 middle(word),
43 end(word)
44 )
45 result.append(curr_word_tuple)
46 return result
47
48#print(beginning('12'))
49#print(middle('12'))
50#print(end('12'))
51#print(split_sentence('Kazvam se Djon Snow'))
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
16.10.2023 21:00
16.10.2023 20:58
16.10.2023 20:59
16.10.2023 21:00
16.10.2023 21:02
16.10.2023 21:02