Answer:
def my_compare(str1, str2):
mylist = sorted([str1, str2])
if str1 == str2:
return 0
elif str1 == mylist[0]:
return -1
elif str1 == mylist[1]:
return 1
def is_char_in(string, char):
if char in string:
return True
return False
def is_char_not_in(string, char):
if char not in string:
return True
return False
def my_count(string, char):
return string.count(char)
def my_endswith(string, char):
return string.endswith(char)
def my_find(string, char):
if char in string:
return string.index(char)
else:
return -1
def my_replace(string, char1, char2):
lst = [i for i in string]
print(lst)
for i, v in enumerate(lst):
if v==char1:
lst[i] = char2
return "".join(lst)
Step-by-step explanation:
Above are defined functions similar to the string built-in functions in python. To use them, type in the function name and pass in the required arguments. Save the file name as "string_functions" with a ".py" file extension and use the functions in other files by importing all the function as "import string_functions" or import individual functions with "from string_function import 'function_name' ".