-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstring_helper.py
25 lines (22 loc) · 910 Bytes
/
string_helper.py
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
# Custom module for Part 7 - Creating your own modules
# String helper - Approach 1
from string import ascii_lowercase, ascii_uppercase, digits
def change_case(orig_string: str) -> str:
mod_string = ""
for character in orig_string:
if character in ascii_lowercase:
mod_string += character.upper()
elif character in ascii_uppercase:
mod_string += character.lower()
else:
mod_string += character
return mod_string
def split_in_half(orig_string: str) -> tuple[str, str]:
half = len(orig_string) // 2
return orig_string[:half], orig_string[half:]
def remove_special_characters(orig_string: str) -> str:
mod_string = ""
for character in orig_string:
if character in ascii_lowercase or character in ascii_uppercase or character in digits or character == " ":
mod_string += character
return mod_string