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)
时间: 2024-10-23 11:05:32