forked from SyedGhazanferAnwar/MailGeek
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstring_utils.py
More file actions
32 lines (25 loc) · 879 Bytes
/
string_utils.py
File metadata and controls
32 lines (25 loc) · 879 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
def reverse_string(input_string: str) -> str:
"""
Reverse the given input string manually, without using slice notation or reverse().
Args:
input_string (str): The string to be reversed.
Returns:
str: The reversed string.
Raises:
TypeError: If the input is not a string.
"""
# Check if input is a string
if not isinstance(input_string, str):
raise TypeError("Input must be a string")
# Convert string to list of characters
chars = list(input_string)
# Manually reverse the list of characters
left, right = 0, len(chars) - 1
while left < right:
# Swap characters
chars[left], chars[right] = chars[right], chars[left]
# Move towards the center
left += 1
right -= 1
# Convert back to string and return
return ''.join(chars)