Discuss / Python / 计算前后空格结束位置即可

计算前后空格结束位置即可

Topic source

Roger_R36

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

    sta,end = 0,0

    i = len(s)

    for n in range(i):

        if s.count(' ',0,n+1) < n+1:

            sta = n   

            break

    for n in range(i):

        if s.count(' ',-n-1) < n+1:

            end = i-n  

            break        

    return s[sta:end]


  • 1

Reply