1def beginning(str):
2 if len(str) % 3 == 2:
3 a = len(str) // 3
4 beg = str[:a + 1]
5 return beg
6 else:
7 a = len(str) // 3
8 beg = str[:a]
9 return beg
10
11def middle(str):
12 if len(str) % 3 == 0:
13 a = len(str) // 3
14 beg = str[a : 2 * a]
15 return beg
16 elif len(str) % 3 == 1:
17 a = len(str) // 3
18 beg = str[a : 2 * a + 1]
19 return beg
20 else:
21 a = len(str) // 3
22 beg = str[a + 1 : 2 * a + 1]
23 return beg
24
25
26def end(str):
27 if len(str) % 3 == 0:
28 a = len(str) // 3
29 beg = str[2 * a : len(str)]
30 return beg
31 else:
32 a = len(str) // 3
33 beg = str[2 * a + 1: len(str)]
34 return beg
35
36def split_sentence(str):
37 arr = []
38 index = 0
39 pom = 0
40 for i in str:
41 index = index + 1
42 if i == ' ':
43 arr.append(str[pom : index - 1])
44 pom = index
45 arr.append(str[pom : len(str)])
46
47 i = 0
48 for e in arr:
49 arr[i] = tuple([beginning(arr[i]), middle(arr[i]), end(arr[i])])
50 i = i + 1
51
52 return arr
53
54
55
56#print(split_sentence("Kazvam se Jhon Snow"))
............
----------------------------------------------------------------------
Ran 12 tests in 0.000s
OK
n | 1 | def begging(str): | n | 1 | def beginning(str): |
2 | if len(str) % 3 == 2: | 2 | if len(str) % 3 == 2: | ||
3 | a = len(str) // 3 | 3 | a = len(str) // 3 | ||
4 | beg = str[:a + 1] | 4 | beg = str[:a + 1] | ||
5 | return beg | 5 | return beg | ||
6 | else: | 6 | else: | ||
7 | a = len(str) // 3 | 7 | a = len(str) // 3 | ||
8 | beg = str[:a] | 8 | beg = str[:a] | ||
9 | return beg | 9 | return beg | ||
10 | 10 | ||||
11 | def middle(str): | 11 | def middle(str): | ||
12 | if len(str) % 3 == 0: | 12 | if len(str) % 3 == 0: | ||
13 | a = len(str) // 3 | 13 | a = len(str) // 3 | ||
14 | beg = str[a : 2 * a] | 14 | beg = str[a : 2 * a] | ||
15 | return beg | 15 | return beg | ||
16 | elif len(str) % 3 == 1: | 16 | elif len(str) % 3 == 1: | ||
17 | a = len(str) // 3 | 17 | a = len(str) // 3 | ||
18 | beg = str[a : 2 * a + 1] | 18 | beg = str[a : 2 * a + 1] | ||
19 | return beg | 19 | return beg | ||
20 | else: | 20 | else: | ||
21 | a = len(str) // 3 | 21 | a = len(str) // 3 | ||
22 | beg = str[a + 1 : 2 * a + 1] | 22 | beg = str[a + 1 : 2 * a + 1] | ||
23 | return beg | 23 | return beg | ||
24 | 24 | ||||
25 | 25 | ||||
26 | def end(str): | 26 | def end(str): | ||
27 | if len(str) % 3 == 0: | 27 | if len(str) % 3 == 0: | ||
28 | a = len(str) // 3 | 28 | a = len(str) // 3 | ||
29 | beg = str[2 * a : len(str)] | 29 | beg = str[2 * a : len(str)] | ||
30 | return beg | 30 | return beg | ||
31 | else: | 31 | else: | ||
32 | a = len(str) // 3 | 32 | a = len(str) // 3 | ||
33 | beg = str[2 * a + 1: len(str)] | 33 | beg = str[2 * a + 1: len(str)] | ||
34 | return beg | 34 | return beg | ||
35 | 35 | ||||
36 | def split_sentence(str): | 36 | def split_sentence(str): | ||
37 | arr = [] | 37 | arr = [] | ||
38 | index = 0 | 38 | index = 0 | ||
39 | pom = 0 | 39 | pom = 0 | ||
40 | for i in str: | 40 | for i in str: | ||
41 | index = index + 1 | 41 | index = index + 1 | ||
42 | if i == ' ': | 42 | if i == ' ': | ||
43 | arr.append(str[pom : index - 1]) | 43 | arr.append(str[pom : index - 1]) | ||
44 | pom = index | 44 | pom = index | ||
45 | arr.append(str[pom : len(str)]) | 45 | arr.append(str[pom : len(str)]) | ||
46 | 46 | ||||
47 | i = 0 | 47 | i = 0 | ||
48 | for e in arr: | 48 | for e in arr: | ||
t | 49 | arr[i] = tuple([begging(arr[i]), middle(arr[i]), end(arr[i])]) | t | 49 | arr[i] = tuple([beginning(arr[i]), middle(arr[i]), end(arr[i])]) |
50 | i = i + 1 | 50 | i = i + 1 | ||
51 | 51 | ||||
52 | return arr | 52 | return arr | ||
53 | 53 | ||||
54 | 54 | ||||
55 | 55 | ||||
56 | #print(split_sentence("Kazvam se Jhon Snow")) | 56 | #print(split_sentence("Kazvam se Jhon Snow")) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def begging(str): | f | 1 | def begging(str): |
2 | if len(str) % 3 == 2: | 2 | if len(str) % 3 == 2: | ||
3 | a = len(str) // 3 | 3 | a = len(str) // 3 | ||
4 | beg = str[:a + 1] | 4 | beg = str[:a + 1] | ||
5 | return beg | 5 | return beg | ||
6 | else: | 6 | else: | ||
7 | a = len(str) // 3 | 7 | a = len(str) // 3 | ||
8 | beg = str[:a] | 8 | beg = str[:a] | ||
9 | return beg | 9 | return beg | ||
10 | 10 | ||||
11 | def middle(str): | 11 | def middle(str): | ||
12 | if len(str) % 3 == 0: | 12 | if len(str) % 3 == 0: | ||
13 | a = len(str) // 3 | 13 | a = len(str) // 3 | ||
14 | beg = str[a : 2 * a] | 14 | beg = str[a : 2 * a] | ||
15 | return beg | 15 | return beg | ||
16 | elif len(str) % 3 == 1: | 16 | elif len(str) % 3 == 1: | ||
17 | a = len(str) // 3 | 17 | a = len(str) // 3 | ||
18 | beg = str[a : 2 * a + 1] | 18 | beg = str[a : 2 * a + 1] | ||
19 | return beg | 19 | return beg | ||
20 | else: | 20 | else: | ||
21 | a = len(str) // 3 | 21 | a = len(str) // 3 | ||
22 | beg = str[a + 1 : 2 * a + 1] | 22 | beg = str[a + 1 : 2 * a + 1] | ||
23 | return beg | 23 | return beg | ||
24 | 24 | ||||
25 | 25 | ||||
26 | def end(str): | 26 | def end(str): | ||
27 | if len(str) % 3 == 0: | 27 | if len(str) % 3 == 0: | ||
28 | a = len(str) // 3 | 28 | a = len(str) // 3 | ||
29 | beg = str[2 * a : len(str)] | 29 | beg = str[2 * a : len(str)] | ||
30 | return beg | 30 | return beg | ||
31 | else: | 31 | else: | ||
32 | a = len(str) // 3 | 32 | a = len(str) // 3 | ||
33 | beg = str[2 * a + 1: len(str)] | 33 | beg = str[2 * a + 1: len(str)] | ||
34 | return beg | 34 | return beg | ||
35 | 35 | ||||
36 | def split_sentence(str): | 36 | def split_sentence(str): | ||
37 | arr = [] | 37 | arr = [] | ||
38 | index = 0 | 38 | index = 0 | ||
39 | pom = 0 | 39 | pom = 0 | ||
40 | for i in str: | 40 | for i in str: | ||
41 | index = index + 1 | 41 | index = index + 1 | ||
42 | if i == ' ': | 42 | if i == ' ': | ||
43 | arr.append(str[pom : index - 1]) | 43 | arr.append(str[pom : index - 1]) | ||
44 | pom = index | 44 | pom = index | ||
45 | arr.append(str[pom : len(str)]) | 45 | arr.append(str[pom : len(str)]) | ||
46 | 46 | ||||
47 | i = 0 | 47 | i = 0 | ||
48 | for e in arr: | 48 | for e in arr: | ||
49 | arr[i] = tuple([begging(arr[i]), middle(arr[i]), end(arr[i])]) | 49 | arr[i] = tuple([begging(arr[i]), middle(arr[i]), end(arr[i])]) | ||
50 | i = i + 1 | 50 | i = i + 1 | ||
n | 51 | n | 51 | ||
52 | return arr | 52 | return arr | ||
53 | 53 | ||||
54 | 54 | ||||
55 | 55 | ||||
t | 56 | print(split_sentence("Kazvam se Jhon Snow")) | t | 56 | #print(split_sentence("Kazvam se Jhon Snow")) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
16.10.2023 14:28
16.10.2023 14:25
16.10.2023 14:26
16.10.2023 14:29