How can I perform this without using any string methods (e.g s.split() )?

def remove_substring_from_string(s, substr):

s2 = s.split()
substr2 = substr.split()    

for x in range(0,len(s2)):
    for y in range(0,len(substr2)):

Removing substring from string

        if (s2[x]==substr2[y]):

Print result

for x in range(0,len(s2)):

Also, using print leads to my output having None in it. So anyway to get rid of that would also be appreciated.

Hi Alexander,

Is there a reason why you don’t want to use string methods? It seems
strange to me. That’s a bit like a carpenter asking how to build a fine
piece of wooden furniture without using any wood-working tools.

“I need to make a chest of drawers using only a soup spoon, an old boot,
and a broom.”

If you really need to do it (to win a bet?) I would start by writing my
own versions of the string methods you use, like split. Something like:

# Warning: this is untested, may contain errors
def mysplit(string):
    pieces = []
    las_position = position = 0
    while position < len(string):
        char = string[position]
        if char == ' ':
            last_position = position+1
    return pieces

and use that instead.