Discuss / Python / 递归算法去空格

递归算法去空格

Topic source

yan32777

#1 Created at ... [Delete] [Delete and Lock User]

def trim(s):

    length=len(s)

    if length>0:

        if s[0]==' ':

            s=s[1:length]

            s=trim(s)

        elif s[-1]==' ':

            s=s[:length-1]

            s=trim(s)

    return s


  • 1

Reply