-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse_string.py
More file actions
40 lines (32 loc) · 908 Bytes
/
reverse_string.py
File metadata and controls
40 lines (32 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def len_str(string):
count = 0
for _ in string:
count += 1
return count
def string_reversed(string):
len_string = len_str(string)-1
# print(len_string)
string_reversed = ''
dict_count = {}
while len_string >= 0:
string_reversed += string[len_string]
if string[len_string] not in dict_count:
dict_count[string[len_string]] = 1
else:
dict_count[string[len_string]] += 1
len_string -= 1
return string_reversed # , dict_count
# print(string_reversed('Hello World!'))
def string_splitter(string):
tmp = ''
splitted_list = []
for c in string:
if c != ' ':
tmp += c
else:
splitted_list += tmp[::-1]
tmp = ''
if tmp:
splitted_list += tmp[::-1]
return ''.join(splitted_list)
print(string_splitter("Hello World"))