Discuss / Python / 来一个递归版的吧

来一个递归版的吧

Topic source
def myTrim(s):
    if len(s) <= 0 or s[0] != ' ' and s[-1] != ' ':
        return s;
    if s[0] == ' ':
        s = s[1:]
    if len(s) > 0 and s[-1] == ' ':
        s = s[:-1]
    return myTrim(s);

print(myTrim('      abasdfaf123123         '))

I just have to saying THIS IS A BEST INSTANCE OF RECURSION brother

安行农园

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

厉害!!


  • 1

Reply