请问这么写为什么会越界?

代码A

def getChild(node,tag):
    for ele in node:
        if ele.tag == tag:
            return ele
result = getChild(getChild(r,'em'),'a')

代码B

def getChild(node,tags):
    if(len(tags) > 0):
        for ele in node:
            if ele.tag == tags[0]:
                del tags[0]
                getChild(ele,tags)
    else:
        return node
result = getChild(r,['em','a'])

简单说就是我想把代码A写成代码B的形式,代码A是没问题的可以通过,但是换成B的形式就通不过了。
最后一次跳出循环后还是会执行if里边的代码导致tags[0]那里数组越界。

讨论数量: 1
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!