def trim(s): if isinstance(s, (str)): return trim_str(s) else: raise TypeError('bad operand type')
def trim_str(s): if len(s) == 0: return s if s[0] == ' ': return trim_str(s[1:]) if s[-1] == ' ': return trim_str(s[:-1]) return s
Sign in to make a reply
skychi
def trim(s): if isinstance(s, (str)): return trim_str(s) else: raise TypeError('bad operand type')
def trim_str(s): if len(s) == 0: return s if s[0] == ' ': return trim_str(s[1:]) if s[-1] == ' ': return trim_str(s[:-1]) return s