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