标签:recursion fun list tool 函数 span tools rom reverse
def reverse_str(s): from functools import reduce res = s[::-1] # 切片 res = "".join(list(reversed(s))) # 反转函数 res = reduce(lambda x,y:y+x, s) # reduce print(res) def recursion_reverse_str(s): # 递归 if len(s) < 1: return "" return recursion_reverse_str(s[1:]) + s[0] def stack_reverse_str(s): # 栈 li = list(s) res = "" while len(li)>0: res += li.pop() return res def loop_str(s): # 循环 res = "" for i in range(len(s)-1, -1, -1): res += s[i] return res
标签:recursion fun list tool 函数 span tools rom reverse
原文地址:https://www.cnblogs.com/demo-deng/p/14711106.html