Python 多维数组求下标

时间:2022-09-03 18:59:56
def list_index(List,sub_ele,Index=[],a=0):    
    for i in List: 
        print 'search...'+`Index`
        if  isinstance(i,list):                 
            Index.append(a)            
            x=list_index(i,sub_ele,Index,a=0)            
            if x:
               return x
            Index.pop()
        elif sub_ele == i:            
            Index.append(a)
            print 'success:'+`Index`
            return Index            
        a+=1
List=['a','i',['b','c'],'e',['f',['g',['z'],['y',['k']],['j',['n',['m'],'w'],'x']],'h'],'l']sub_ele='y'print list_index(List,sub_ele)


本文出自 “运维学习之路” 博客,请务必保留此出处http://kk15320.blog.51cto.com/4848160/1891215