Discuss / Python / Easy Method

Easy Method

Topic source
def trim(s):
    start = 0    end = len(s)
    while True:
        if s[start:start + 1] != ' ' and s[end - 1:end] != ' ':
            break        elif s[start:start + 1] == ' ':
            start = start + 1        elif s[end - 1:end] == ' ':
            end = end - 1    return s[start:end]

  • 1

Reply