如何递归执行此功能? [英] How do I perform this function recursively?

查看:78
本文介绍了如何递归执行此功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

# totalIndexSeq = ['0+234+6+', '++++++', '012++5678']

< br $>


def longestSeqFinder(totalIndexSeq):
    positionCounter = 0
    positionChecker = 0
    tryList = []
    longestSeqList = []

    for y in totalIndexSeq:

        temp = y.split("+")
        tryList.append(temp)

    for i in tryList:
        longestSeq = (max(i, key = len))
        longestSeqList.append(longestSeq)





我尝试了什么:



我是编码的新手,我老实说不知道从哪里开始。



What I have tried:

I am new to coding, and I'm honestly not sure where to begin.

推荐答案

递归意味着函数调用自身。如果你的函数调用自己,那就是使用递归。递归的一个明显用途是导航树,该方法总是遍历节点的子节点,并调用自身。当树结束时,递归结束。



我有面试问题,要求我写一个递归函数,这是没有意义的。递归并不复杂,有大量的教程和示例。如果你想学习递归,我建议起点是使用一个有意义的例子
Recursion means the function calls itself. If your function calls itself, it's using recursion. An obvious use for recursion would be to navigate a tree, the method always goes through the children of a node, and calls itself. When the tree ends, the recursion ends.

I've had interview questions that ask me to write a recursive function where it makes no sense. Recursion is not a complex thing, there's tons of tutorials and examples. If you want to learn recursion, I'd suggest the starting point is using an example where it makes sense to use it


这篇关于如何递归执行此功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆