Discuss / Python / 效率

效率

Topic source

zengdb

#1 Created at ... [Delete] [Delete and Lock User]
    b=0  # begin position
    while s[b:(b+1)]==' ':
     b=b+1
    
    if s[-1:]==' ':
        x=-1  # end position
        while s[(x-1):x]==' ':
            x=x-1
        return s[i:x]
    else:
        return s[i:]

我的代码要复杂一些,但是我觉得效率更高,因为没有做反复的字符串复制,判断好首尾直接一次切片。


  • 1

Reply