Python 递归函数未返回正确的值

Python 递归函数未返回正确的值,python,Python,我编写了一个递归函数,它检查列表中的一个值,并在获得所需值后立即存储索引,我使用return语句退出该函数,即使它从子函数中退出,也不会从父函数中退出。是否有我缺少的东西限制了它在找到值后完全退出函数 new_index=[] def check_with_list(dd,check_value): global new_index for index,h in enumerate(dd): if isinstance(h, list):

我编写了一个递归函数,它检查列表中的一个值,并在获得所需值后立即存储索引,我使用return语句退出该函数,即使它从子函数中退出,也不会从父函数中退出。是否有我缺少的东西限制了它在找到值后完全退出函数

new_index=[]
def check_with_list(dd,check_value):
    global  new_index

    for index,h in enumerate(dd):
        if isinstance(h, list):
            new_index.append(index)
            check_with_list(h,check_value)
        elif h==check_value:
            new_index.append(index)
            import pdb;pdb.set_trace()
            return new_index
    else:
        new_index=[]



dd=['gcc','fcc',['scc','jhh'],['www','rrr','rrr']]
dd=check_with_list(dd,'rrr')

print dd

在子列表上调用
check\u with\u list
时,不会返回结果

def check_with_list(dd, check_value):
    for index,h in enumerate(dd):
        if isinstance(h, list):
            result = check_with_list(h,check_value)
            if result is not None:
                return (index,) + result 
        elif h == check_value:
            return (index,)
    # value not found
    return None


dd=['gcc','fcc',['scc','jhh'],['www','rrr','rrr']]
dd=check_with_list(dd,'rrr')

print dd

你能调查一下我现在的问题吗,