标签:else 递归算法 att get dir 需要 instance 显示 print
def get_file_recur(path):
children = os.listdir(path)
for child in children:
qualified_child = os.path.join(path,child)
if os.path.isfile(qualified_child):
yield qualified_child
else:
tmp = get_file_recur(qualified_child)
for item in tmp:
yield item
for file in get_file_recur('/home/xxx/xxx/Frank Li'):
print(file)
def flattern(lst):
for item in lst:
if isinstance(item,list):
inner_list = flattern(item)
for i in inner_list:
yield i
else:
yield item
l=[1,2,3,4,5,[6],[7,8,[9,[10]]]]
lst=flattern(l)
print(list(lst))
标签:else 递归算法 att get dir 需要 instance 显示 print
原文地址:https://www.cnblogs.com/Frank99/p/9563980.html