def wstrip(s, word, left=True, right=True):
    """Strip word from the beginning or the end of the string.
    By default strips from both sides.
    """
    step = len(word)
    start_pos = None
    end_pos = None

    if not word:
        return s

    while True:
        found = False
        if left and s.startswith(word, start_pos, end_pos):
            if start_pos is None:
                start_pos = 0
            start_pos += step
            found = True
        if right and s.endswith(word, start_pos, end_pos):
            if end_pos is None:
                end_pos = 0
            end_pos -= step
            found = True
        if not found:
            break

    return s[start_pos:end_pos]