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)
转载于:https://blog.51cto.com/kk15320/1891215